Skip to content

Commit

Permalink
fix(example/http): Fixed potential memory leak/crash in when handling…
Browse files Browse the repository at this point in the history
… error condition
  • Loading branch information
Zim Kalinowski authored and mahavirj committed Dec 13, 2023
1 parent 9fe3bf2 commit 2e9999d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions examples/protocols/https_request/main/time_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ static void obtain_time(void)

void fetch_and_store_time_in_nvs(void *args)
{
nvs_handle_t my_handle = 0;
esp_err_t err;

initialize_sntp();
obtain_time();

nvs_handle_t my_handle;
esp_err_t err;

time_t now;
time(&now);

Expand All @@ -88,10 +88,12 @@ void fetch_and_store_time_in_nvs(void *args)
goto exit;
}

nvs_close(my_handle);
exit:
if (my_handle != 0) {
nvs_close(my_handle);
}
esp_sntp_stop();

exit:
if (err != ESP_OK) {
ESP_LOGE(TAG, "Error updating time in nvs");
} else {
Expand All @@ -101,7 +103,7 @@ void fetch_and_store_time_in_nvs(void *args)

esp_err_t update_time_from_nvs(void)
{
nvs_handle_t my_handle;
nvs_handle_t my_handle = 0;
esp_err_t err;

err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
Expand All @@ -123,6 +125,8 @@ esp_err_t update_time_from_nvs(void)
}

exit:
nvs_close(my_handle);
if (my_handle != 0) {
nvs_close(my_handle);
}
return err;
}

0 comments on commit 2e9999d

Please sign in to comment.