Skip to content

Commit

Permalink
Merge branch 'bugfix/fix-clean-up-in-error-condition-in-http-example_…
Browse files Browse the repository at this point in the history
…v5.0' into 'release/v5.0'

fix(example/http): Fixed potential memory leak/crash in when handling error condition (v5.0)

See merge request espressif/esp-idf!27876
  • Loading branch information
mahavirj committed Dec 20, 2023
2 parents a20d0b2 + 2e9999d commit 4272b44
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 4272b44

Please sign in to comment.