mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
fix(example/http): Fixed potential memory leak/crash in when handling error condition
This commit is contained in:
committed by
Mahavir Jain
parent
9fe3bf2a3c
commit
2e9999d7b1
@@ -62,12 +62,12 @@ static void obtain_time(void)
|
|||||||
|
|
||||||
void fetch_and_store_time_in_nvs(void *args)
|
void fetch_and_store_time_in_nvs(void *args)
|
||||||
{
|
{
|
||||||
|
nvs_handle_t my_handle = 0;
|
||||||
|
esp_err_t err;
|
||||||
|
|
||||||
initialize_sntp();
|
initialize_sntp();
|
||||||
obtain_time();
|
obtain_time();
|
||||||
|
|
||||||
nvs_handle_t my_handle;
|
|
||||||
esp_err_t err;
|
|
||||||
|
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
|
|
||||||
@@ -88,10 +88,12 @@ void fetch_and_store_time_in_nvs(void *args)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (my_handle != 0) {
|
||||||
nvs_close(my_handle);
|
nvs_close(my_handle);
|
||||||
|
}
|
||||||
esp_sntp_stop();
|
esp_sntp_stop();
|
||||||
|
|
||||||
exit:
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Error updating time in nvs");
|
ESP_LOGE(TAG, "Error updating time in nvs");
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +103,7 @@ exit:
|
|||||||
|
|
||||||
esp_err_t update_time_from_nvs(void)
|
esp_err_t update_time_from_nvs(void)
|
||||||
{
|
{
|
||||||
nvs_handle_t my_handle;
|
nvs_handle_t my_handle = 0;
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
|
|
||||||
err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
|
err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
|
||||||
@@ -123,6 +125,8 @@ esp_err_t update_time_from_nvs(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (my_handle != 0) {
|
||||||
nvs_close(my_handle);
|
nvs_close(my_handle);
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user