From 6247ee066dd912f9e88b7914bb3d956936967c69 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 29 Dec 2025 20:08:34 +0100 Subject: [PATCH] fix presets.json corruption, part 1: avoid re-assigning open file pointer * this prevents "open after open", that could lead to file corruption when "f" was still holding some changes in its buffer (written out with f.close()) --- wled00/file.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wled00/file.cpp b/wled00/file.cpp index bb853df9..bf8ef929 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -299,6 +299,11 @@ bool writeObjectToFile(const char* file, const char* key, JsonDocument* content) s = millis(); #endif + if (doCloseFile) { + if (f) { DEBUG_PRINTLN("writeObjectToFile("+String(file)+"): file f is already open, closing to prevent file corruption."); } + closeFile(); // WLEDMM: Ensure previous file is closed + } + size_t pos = 0; f = WLED_FS.open(file, "r+"); if (!f && !WLED_FS.exists(file)) { f = WLED_FS.open(file, "w+");