Skip to content

Commit fbe5f74

Browse files
committed
app/env: nvs_close() should be called before return
1 parent 8123052 commit fbe5f74

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

main/src/core/app.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ esp_err_t app_getenv(const char *key, void *out_value, size_t *length)
4040
err = nvs_get_blob(handle, key, out_value, length);
4141
if (err == ESP_ERR_NVS_NOT_FOUND) {
4242
ESP_LOGW(TAG, "env \"%s\" not found", key);
43+
nvs_close(handle);
4344
return err;
4445
} else if (err != ESP_OK) {
4546
ESP_LOGE(TAG, "read env \"%s\" failed", key);
47+
nvs_close(handle);
4648
return err;
4749
}
4850

@@ -64,18 +66,18 @@ esp_err_t app_setenv(const char *key, const void *value, size_t length)
6466
err = nvs_set_blob(handle, key, value, length);
6567
if (err != ESP_OK) {
6668
ESP_LOGE(TAG, "set nvs blob failed");
69+
nvs_close(handle);
6770
return err;
6871
}
6972

7073
err = nvs_commit(handle);
7174
if (err != ESP_OK) {
7275
ESP_LOGE(TAG, "write env \"%s\" failed", key);
76+
nvs_close(handle);
7377
return err;
7478
}
7579

7680
nvs_close(handle);
7781

78-
ESP_LOGI(TAG, "env \"%s\" updated", key);
79-
8082
return ESP_OK;
8183
}

0 commit comments

Comments
 (0)