Skip to content

Commit

Permalink
Fix null pointer exception for external client.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Sep 12, 2023
1 parent f2753c6 commit ac006e6
Show file tree
Hide file tree
Showing 31 changed files with 56 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/ExternalClient/Generic/Basic/Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=Firebase ESP32 Client

version=4.4.3
version=4.4.4

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Const.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Error.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Network.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Utils.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/FirebaseFS.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 14 additions & 8 deletions src/core/FirebaseCore.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/core/FirebaseCore.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/core/Firebase_Client_Version.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/message/FCM.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/message/FCM.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/message/LFCM.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/FB_RTDB.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/FB_RTDB.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueryFilter.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueryFilter.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueInfo.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueInfo.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueManager.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueManager.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_MP_Stream.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_MP_Stream.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_Stream.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_Stream.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 7 additions & 8 deletions src/session/FB_Session.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/session/FB_Session.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit ac006e6

Please sign in to comment.