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.1' into 'release/v5.1'

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

See merge request espressif/esp-idf!27875
  • Loading branch information
mahavirj committed Dec 20, 2023
2 parents 2c564d3 + 4c93085 commit b38ee33
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions examples/protocols/https_request/main/time_sync.c
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -54,14 +54,15 @@ static esp_err_t obtain_time(void)

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

initialize_sntp();
if (obtain_time() != ESP_OK) {
return ESP_FAIL;
err = ESP_FAIL;
goto exit;
}

nvs_handle_t my_handle;
esp_err_t err;

time_t now;
time(&now);

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

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

exit:
if (err != ESP_OK) {
ESP_LOGE(TAG, "Error updating time in nvs");
} else {
Expand All @@ -96,7 +99,7 @@ esp_err_t 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 @@ -122,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 b38ee33

Please sign in to comment.