mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
examples: Fixing possible memory leak, not freeing "run_time" prior to returning
Merges https://github.com/espressif/esp-idf/pull/2367
This commit is contained in:
parent
c15e7b18f8
commit
17177e352b
@ -80,7 +80,10 @@ esp_err_t save_run_time(void)
|
||||
uint32_t* run_time = malloc(required_size + sizeof(uint32_t));
|
||||
if (required_size > 0) {
|
||||
err = nvs_get_blob(my_handle, "run_time", run_time, &required_size);
|
||||
if (err != ESP_OK) return err;
|
||||
if (err != ESP_OK) {
|
||||
free(run_time);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
// Write value including previously saved blob if available
|
||||
@ -131,7 +134,10 @@ esp_err_t print_what_saved(void)
|
||||
} else {
|
||||
uint32_t* run_time = malloc(required_size);
|
||||
err = nvs_get_blob(my_handle, "run_time", run_time, &required_size);
|
||||
if (err != ESP_OK) return err;
|
||||
if (err != ESP_OK) {
|
||||
free(run_time);
|
||||
return err;
|
||||
}
|
||||
for (int i = 0; i < required_size / sizeof(uint32_t); i++) {
|
||||
printf("%d: %d\n", i + 1, run_time[i]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user