Skip to content

Commit

Permalink
Fix issue #148 ESP32 memory leak due to RTOS stack memory release issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Oct 7, 2021
1 parent 517d237 commit 14ac5b3
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 86 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.5.3
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.5.4


This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only).
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 Arduino Client Library for ESP8266 and ESP32",
"version": "2.5.3",
"version": "2.5.4",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "The library supports Firebase products e.g. Realtime database, Cloud Firestore database, Firebase Storage and Google Cloud Storage, Cloud Functions for Firebase and Cloud Messaging.",
"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 Arduino Client Library for ESP8266 and ESP32

version=2.5.3
version=2.5.4

author=Mobizt

Expand Down
9 changes: 4 additions & 5 deletions src/Firebase_ESP_Client.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#ifndef FIREBASE_CLIENT_VERSION
#define FIREBASE_CLIENT_VERSION "2.5.3"
#define FIREBASE_CLIENT_VERSION "2.5.4"
#endif

/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v2.5.3
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v2.5.4
*
* This library supports Espressif ESP8266 and ESP32 MCUs
*
* Created October 6, 2021
* Created October 7, 2021
*
* Updates:
* - Add support user re-authentication.
* - Add re-authenticate example.
* - Fix issue #148 ESP32 memory leak due to RTOS stack memory release issue.
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.5.3
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.5.4


The default filessystem used in the library is flash and SD.
Expand Down
3 changes: 1 addition & 2 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Created September 20, 2021
* Created October 7, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -731,7 +731,6 @@ struct fb_esp_cfg_int_t
TaskHandle_t resumable_upload_task_handle = NULL;
TaskHandle_t functions_check_task_handle = NULL;
TaskHandle_t functions_deployment_task_handle = NULL;
TaskHandle_t token_processing_task_handle = NULL;
#endif
};

Expand Down
138 changes: 65 additions & 73 deletions src/signer/Signer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase Token Generation class, Signer.cpp version 1.2.2
* Google's Firebase Token Generation class, Signer.cpp version 1.2.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created September 20, 2021
* Created October 7, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -307,102 +307,94 @@ bool Firebase_Signer::handleToken()

void Firebase_Signer::tokenProcessingTask()
{

#if defined(ESP32)

if (config->signer.tokenTaskRunning)
return;

static Firebase_Signer *_this = this;
bool ret = false;

TaskFunction_t taskCode = [](void *param)
{
_this->config->signer.tokenTaskRunning = true;
config->signer.tokenTaskRunning = true;

while (_this->_token_processing_task_enable)
while (!ret)
{
delay(0);

if (config->signer.tokens.token_type == token_type_id_token)
{
vTaskDelay(20 / portTICK_PERIOD_MS);
config->signer.lastReqMillis = millis();

if (_this->config->signer.tokens.token_type == token_type_id_token)
if (getIdToken(false, "", ""))
{
_this->config->signer.lastReqMillis = millis();
if (_this->getIdToken(false, "", ""))
{
_this->_token_processing_task_enable = false;
_this->config->signer.attempts = 0;
break;
}
_token_processing_task_enable = false;
config->signer.attempts = 0;
ret = true;
}
else
{
if (config->signer.attempts < config->max_token_generation_retry)
config->signer.attempts++;
else
{
if (_this->config->signer.attempts < _this->config->max_token_generation_retry)
_this->config->signer.attempts++;
else
{
_this->ut->clearS(_this->config->signer.tokens.error.message);
_this->setTokenError(FIREBASE_ERROR_TOKEN_EXCHANGE_MAX_RETRY_REACHED);
_this->sendTokenStatusCB();
_this->_token_processing_task_enable = false;
_this->config->signer.attempts = 0;
break;
}
ut->clearS(config->signer.tokens.error.message);
setTokenError(FIREBASE_ERROR_TOKEN_EXCHANGE_MAX_RETRY_REACHED);
sendTokenStatusCB();
_token_processing_task_enable = false;
config->signer.attempts = 0;
ret = true;
}
}
else
}
else
{
if (config->signer.step == fb_esp_jwt_generation_step_begin)
{
if (_this->config->signer.step == fb_esp_jwt_generation_step_begin)
{
_this->ut->setClock(_this->config->time_zone);
time_t now = time(nullptr);
_this->config->_int.fb_clock_rdy = now > _this->ut->default_ts;
ut->setClock(config->time_zone);
time_t now = time(nullptr);
config->_int.fb_clock_rdy = now > ut->default_ts;

if (_this->config->_int.fb_clock_rdy)
_this->config->signer.step = fb_esp_jwt_generation_step_encode_header_payload;
}
else if (_this->config->signer.step == fb_esp_jwt_generation_step_encode_header_payload)
{
if (_this->createJWT())
_this->config->signer.step = fb_esp_jwt_generation_step_sign;
}
else if (_this->config->signer.step == fb_esp_jwt_generation_step_sign)
if (config->_int.fb_clock_rdy)
config->signer.step = fb_esp_jwt_generation_step_encode_header_payload;
}
else if (config->signer.step == fb_esp_jwt_generation_step_encode_header_payload)
{
if (createJWT())
config->signer.step = fb_esp_jwt_generation_step_sign;
}
else if (config->signer.step == fb_esp_jwt_generation_step_sign)
{
if (createJWT())
config->signer.step = fb_esp_jwt_generation_step_exchange;
}
else if (config->signer.step == fb_esp_jwt_generation_step_exchange)
{
if (requestTokens())
{
if (_this->createJWT())
_this->config->signer.step = fb_esp_jwt_generation_step_exchange;
config->signer.attempts = 0;
_token_processing_task_enable = false;
config->signer.step = fb_esp_jwt_generation_step_begin;
ret = true;
}
else if (_this->config->signer.step == fb_esp_jwt_generation_step_exchange)
else
{
if (_this->requestTokens())
{
_this->config->signer.attempts = 0;
_this->_token_processing_task_enable = false;
_this->config->signer.step = fb_esp_jwt_generation_step_begin;
break;
}
if (config->signer.attempts < config->max_token_generation_retry)
config->signer.attempts++;
else
{
if (_this->config->signer.attempts < _this->config->max_token_generation_retry)
_this->config->signer.attempts++;
else
{
_this->ut->clearS(_this->config->signer.tokens.error.message);
_this->setTokenError(FIREBASE_ERROR_TOKEN_EXCHANGE_MAX_RETRY_REACHED);
_this->sendTokenStatusCB();
_this->config->signer.attempts = 0;
_this->config->signer.step = fb_esp_jwt_generation_step_begin;
break;
}
ut->clearS(config->signer.tokens.error.message);
setTokenError(FIREBASE_ERROR_TOKEN_EXCHANGE_MAX_RETRY_REACHED);
sendTokenStatusCB();
config->signer.attempts = 0;
config->signer.step = fb_esp_jwt_generation_step_begin;
ret = true;
}
}
}

yield();
}
_this->config->_int.token_processing_task_handle = NULL;
_this->config->signer.tokenTaskRunning = false;
vTaskDelete(NULL);
};

char *taskname = ut->strP(fb_esp_pgm_str_546);
xTaskCreatePinnedToCore(taskCode, taskname, 12000, NULL, 3, &config->_int.token_processing_task_handle, 1);
ut->delS(taskname);
}

config->signer.tokenTaskRunning = false;

#elif defined(ESP8266)

Expand Down
4 changes: 2 additions & 2 deletions src/signer/Signer.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase Token Generation class, Signer.h version 1.2.2
* Google's Firebase Token Generation class, Signer.h version 1.2.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created September 20, 2021
* Created October 7, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down

0 comments on commit 14ac5b3

Please sign in to comment.