fix(nvs): Close NVS handle after processing key-value pairs to prevent resource leaks

This commit is contained in:
GW_MC
2026-04-20 15:11:56 +08:00
parent c5d6cfcd22
commit 48c6b97062

View File

@@ -129,6 +129,7 @@ esp_err_t NVSStorageHandler::process_all(KeyValueProcessor processor, void* arg)
// call the processor with the key and value // call the processor with the key and value
std::string key_str = info.key; std::string key_str = info.key;
processor(arg, key_str, this->get(key_str)); processor(arg, key_str, this->get(key_str));
nvs_close(temp_handle);
} }
return ESP_OK; return ESP_OK;
} }
@@ -156,6 +157,7 @@ esp_err_t NVSStorageHandler::process_filtered(const std::string& key_prefix, Key
} }
// call the processor with the key and value // call the processor with the key and value
processor(arg, std::string(info.key), this->get(std::string(info.key))); processor(arg, std::string(info.key), this->get(std::string(info.key)));
nvs_close(temp_handle);
} }
} }
return ESP_OK; return ESP_OK;
@@ -186,6 +188,7 @@ esp_err_t NVSStorageHandler::process_filtered(FilterFunc filter_func, KeyValuePr
} }
// call the processor with the key and value // call the processor with the key and value
processor(arg, key_str, this->get(key_str)); processor(arg, key_str, this->get(key_str));
nvs_close(temp_handle);
} }
} }
return ESP_OK; return ESP_OK;