From ac006e64a911709058081b7c3afaf945674a630f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 12 Sep 2023 14:17:24 +0700 Subject: [PATCH] Fix null pointer exception for external client. --- .../ExternalClient/Generic/Basic/Basic.ino | 2 +- .../Generic/StreamCallback/StreamCallback.ino | 4 ++-- library.json | 2 +- library.properties | 2 +- src/FB_Const.h | 2 +- src/FB_Error.h | 2 +- src/FB_Network.h | 2 +- src/FB_Utils.h | 2 +- src/Firebase.cpp | 2 +- src/Firebase.h | 2 +- src/FirebaseFS.h | 2 +- src/core/FirebaseCore.cpp | 22 ++++++++++++------- src/core/FirebaseCore.h | 6 ++--- src/core/Firebase_Client_Version.h | 4 ++-- src/message/FCM.cpp | 2 +- src/message/FCM.h | 2 +- src/message/LFCM.h | 2 +- src/rtdb/FB_RTDB.cpp | 2 +- src/rtdb/FB_RTDB.h | 2 +- src/rtdb/QueryFilter.cpp | 2 +- src/rtdb/QueryFilter.h | 2 +- src/rtdb/QueueInfo.cpp | 2 +- src/rtdb/QueueInfo.h | 2 +- src/rtdb/QueueManager.cpp | 2 +- src/rtdb/QueueManager.h | 2 +- src/rtdb/stream/FB_MP_Stream.cpp | 2 +- src/rtdb/stream/FB_MP_Stream.h | 2 +- src/rtdb/stream/FB_Stream.cpp | 2 +- src/rtdb/stream/FB_Stream.h | 2 +- src/session/FB_Session.cpp | 15 ++++++------- src/session/FB_Session.h | 6 ++--- 31 files changed, 56 insertions(+), 51 deletions(-) diff --git a/examples/ExternalClient/Generic/Basic/Basic.ino b/examples/ExternalClient/Generic/Basic/Basic.ino index 9df0fb70..1c1d22ba 100644 --- a/examples/ExternalClient/Generic/Basic/Basic.ino +++ b/examples/ExternalClient/Generic/Basic/Basic.ino @@ -54,7 +54,7 @@ void networkConnection() void networkStatusRequestCallback() { // Set the network status based on your network client - fbdo.setNetworkStatus(true/* or false */); + fbdo.setNetworkStatus(false /* or true */); } void setup() diff --git a/examples/ExternalClient/Generic/StreamCallback/StreamCallback.ino b/examples/ExternalClient/Generic/StreamCallback/StreamCallback.ino index faad2399..beb1f2e1 100644 --- a/examples/ExternalClient/Generic/StreamCallback/StreamCallback.ino +++ b/examples/ExternalClient/Generic/StreamCallback/StreamCallback.ino @@ -57,8 +57,8 @@ void networkConnection() void networkStatusRequestCallback() { // Set the network status based on your network client - fbdo.setNetworkStatus(true /* or false */); - stream.setNetworkStatus(true /* or false */); + fbdo.setNetworkStatus(false /* or true */); + stream.setNetworkStatus(false /* or true */); } void streamCallback(StreamData data) diff --git a/library.json b/library.json index 7393e20a..f5dca29c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Firebase ESP32 Client", - "version": "4.4.3", + "version": "4.4.4", "keywords": "communication, REST, esp32, arduino", "description": "The secure, fast and reliable Firebase Realtime database library to read, store, update, delete, listen, backup, and restore data. You can also read and modify the database security rules with this library.", "repository": { diff --git a/library.properties b/library.properties index 2323a43e..d4684436 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=Firebase ESP32 Client -version=4.4.3 +version=4.4.4 author=Mobizt diff --git a/src/FB_Const.h b/src/FB_Const.h index a80e2840..d7d71751 100644 --- a/src/FB_Const.h +++ b/src/FB_Const.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/FB_Error.h b/src/FB_Error.h index ad719e35..61ba1d38 100644 --- a/src/FB_Error.h +++ b/src/FB_Error.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/FB_Network.h b/src/FB_Network.h index 645929f0..eb0cd292 100644 --- a/src/FB_Network.h +++ b/src/FB_Network.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/FB_Utils.h b/src/FB_Utils.h index 2a8b8813..28bf5269 100644 --- a/src/FB_Utils.h +++ b/src/FB_Utils.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/Firebase.cpp b/src/Firebase.cpp index 4aa65f44..3a44e408 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/Firebase.h b/src/Firebase.h index b7f1fde1..04dd6d44 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/FirebaseFS.h b/src/FirebaseFS.h index 7f68a873..5e830e1d 100644 --- a/src/FirebaseFS.h +++ b/src/FirebaseFS.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/core/FirebaseCore.cpp b/src/core/FirebaseCore.cpp index 9805847f..e2485125 100644 --- a/src/core/FirebaseCore.cpp +++ b/src/core/FirebaseCore.cpp @@ -1,12 +1,12 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif /** - * Google's Firebase Token Management class, FirebaseCore.cpp version 1.0.0 + * Google's Firebase Token Management class, FirebaseCore.cpp version 1.0.1 * - * Created September 5, 2023 + * Created September 12, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -939,9 +939,15 @@ void FirebaseCore::freeClient(Firebase_TCP_Client **client) _password = (*client)->_password; #endif } - delete *client; + + // Only internal client can be deleted + if (_cli_type == firebase_client_type_internal_basic_client) + delete *client; } - *client = nullptr; + + // Reset pointer in case internal client + if (_cli_type == firebase_client_type_internal_basic_client) + *client = nullptr; } void FirebaseCore::setTokenError(int code) @@ -1708,12 +1714,12 @@ bool FirebaseCore::reconnect() // otherwise the networkStatus will not update // and network cannot resume. - if (noClient) + if (noClient) newClient(&tcpClient); - reconnect(tcpClient, nullptr); + reconnect(tcpClient, nullptr); - if (noClient) + if (noClient) freeClient(&tcpClient); networkChecking = false; diff --git a/src/core/FirebaseCore.h b/src/core/FirebaseCore.h index 70bb8468..ff4acb94 100644 --- a/src/core/FirebaseCore.h +++ b/src/core/FirebaseCore.h @@ -1,12 +1,12 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif /** - * Google's Firebase Token Management class, FirebaseCore.h version 1.0.0 + * Google's Firebase Token Management class, FirebaseCore.h version 1.0.1 * - * Created September 5, 2023 + * Created September 12, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) diff --git a/src/core/Firebase_Client_Version.h b/src/core/Firebase_Client_Version.h index 48d02696..d9356454 100644 --- a/src/core/Firebase_Client_Version.h +++ b/src/core/Firebase_Client_Version.h @@ -1,6 +1,6 @@ #ifndef FIREBASE_CLIENT_VERSION -#define FIREBASE_CLIENT_VERSION "4.4.3" -#define FIREBASE_CLIENT_VERSION_NUM 40403 +#define FIREBASE_CLIENT_VERSION "4.4.4" +#define FIREBASE_CLIENT_VERSION_NUM 40404 /* The inconsistent file version checking to prevent mixed versions compilation. */ #define FIREBASE_CLIENT_VERSION_CHECK(ver) (ver == FIREBASE_CLIENT_VERSION_NUM) diff --git a/src/message/FCM.cpp b/src/message/FCM.cpp index 783a0c57..ea2a4f06 100644 --- a/src/message/FCM.cpp +++ b/src/message/FCM.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/message/FCM.h b/src/message/FCM.h index 1001ac21..9b30cfd3 100644 --- a/src/message/FCM.h +++ b/src/message/FCM.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/message/LFCM.h b/src/message/LFCM.h index 640a3859..aa8682d9 100644 --- a/src/message/LFCM.h +++ b/src/message/LFCM.h @@ -1,6 +1,6 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/FB_RTDB.cpp b/src/rtdb/FB_RTDB.cpp index ae34d863..5ba8d191 100644 --- a/src/rtdb/FB_RTDB.cpp +++ b/src/rtdb/FB_RTDB.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/FB_RTDB.h b/src/rtdb/FB_RTDB.h index be4bcd6a..643a779a 100644 --- a/src/rtdb/FB_RTDB.h +++ b/src/rtdb/FB_RTDB.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/QueryFilter.cpp b/src/rtdb/QueryFilter.cpp index 76f3ae2b..f803df6b 100644 --- a/src/rtdb/QueryFilter.cpp +++ b/src/rtdb/QueryFilter.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/QueryFilter.h b/src/rtdb/QueryFilter.h index 2220f893..028ce3f2 100644 --- a/src/rtdb/QueryFilter.h +++ b/src/rtdb/QueryFilter.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/QueueInfo.cpp b/src/rtdb/QueueInfo.cpp index 4d4ac4ba..01d2bc3e 100644 --- a/src/rtdb/QueueInfo.cpp +++ b/src/rtdb/QueueInfo.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/QueueInfo.h b/src/rtdb/QueueInfo.h index ccbac6d6..0e4e8a87 100644 --- a/src/rtdb/QueueInfo.h +++ b/src/rtdb/QueueInfo.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/QueueManager.cpp b/src/rtdb/QueueManager.cpp index e8309ca4..8979ba87 100644 --- a/src/rtdb/QueueManager.cpp +++ b/src/rtdb/QueueManager.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/QueueManager.h b/src/rtdb/QueueManager.h index c0e8c403..743dc786 100644 --- a/src/rtdb/QueueManager.h +++ b/src/rtdb/QueueManager.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/stream/FB_MP_Stream.cpp b/src/rtdb/stream/FB_MP_Stream.cpp index dd106a89..f353f4a7 100644 --- a/src/rtdb/stream/FB_MP_Stream.cpp +++ b/src/rtdb/stream/FB_MP_Stream.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/stream/FB_MP_Stream.h b/src/rtdb/stream/FB_MP_Stream.h index 213ecc03..b05b4a4b 100644 --- a/src/rtdb/stream/FB_MP_Stream.h +++ b/src/rtdb/stream/FB_MP_Stream.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/stream/FB_Stream.cpp b/src/rtdb/stream/FB_Stream.cpp index 8697e4cb..e9e91318 100644 --- a/src/rtdb/stream/FB_Stream.cpp +++ b/src/rtdb/stream/FB_Stream.cpp @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/rtdb/stream/FB_Stream.h b/src/rtdb/stream/FB_Stream.h index a95a0283..7a9df4c6 100644 --- a/src/rtdb/stream/FB_Stream.h +++ b/src/rtdb/stream/FB_Stream.h @@ -1,5 +1,5 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif diff --git a/src/session/FB_Session.cpp b/src/session/FB_Session.cpp index 249d8ee2..3f6a9f55 100644 --- a/src/session/FB_Session.cpp +++ b/src/session/FB_Session.cpp @@ -1,12 +1,12 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif /** - * Google's Firebase Data class, FB_Session.cpp version 1.4.0 + * Google's Firebase Data class, FB_Session.cpp version 1.4.1 * - * Created September 5, 2023 + * Created September 12, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -74,14 +74,13 @@ FirebaseData::~FirebaseData() void FirebaseData::setGenericClient(Client *client, FB_NetworkConnectionRequestCallback networkConnectionCB, FB_NetworkStatusRequestCallback networkStatusCB) { - if (client) + if (client && networkConnectionCB && networkStatusCB) { _client = client; - Core.setTCPClient(&tcpClient); + tcpClient.setClient(_client, networkConnectionCB, networkStatusCB); } - - if (_networkConnectionCB && _networkStatusCB) - tcpClient.setClient(_client, _networkConnectionCB, _networkStatusCB); + // Client type shall be set before calling this. + Core.setTCPClient(&tcpClient); } void FirebaseData::setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password) diff --git a/src/session/FB_Session.h b/src/session/FB_Session.h index 58b4403f..07d8e085 100644 --- a/src/session/FB_Session.h +++ b/src/session/FB_Session.h @@ -1,12 +1,12 @@ #include "./core/Firebase_Client_Version.h" -#if !FIREBASE_CLIENT_VERSION_CHECK(40403) +#if !FIREBASE_CLIENT_VERSION_CHECK(40404) #error "Mixed versions compilation." #endif /** - * Google's Firebase Data class, FB_Session.h version 1.4.0 + * Google's Firebase Data class, FB_Session.h version 1.4.1 * - * Created September 5, 2023 + * Created September 12, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt)