From 8e27fe4c0cefeacfac2a39078971260a9a245828 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 5 Jan 2026 13:21:37 +0100 Subject: [PATCH 1/2] bufgix: prevent file data loss due to replacing an open file pointer partial fix for #5275 --- wled00/file.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wled00/file.cpp b/wled00/file.cpp index ba406ba3b5..f65bacb487 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -38,7 +38,7 @@ void closeFile() { DEBUGFS_PRINT(F("Close -> ")); uint32_t s = millis(); #endif - f.close(); + if (f) f.close(); // only close if we have an open file DEBUGFS_PRINTF("took %lu ms\n", millis() - s); doCloseFile = false; } @@ -271,6 +271,8 @@ bool writeObjectToFile(const char* file, const char* key, const JsonDocument* co s = millis(); #endif + if (doCloseFile) closeFile(); // This prevents the loss of file data that is still cached in the File object. + size_t pos = 0; char fileName[129]; strncpy_P(fileName, file, 128); fileName[128] = 0; //use PROGMEM safe copy as FS.open() does not f = WLED_FS.open(fileName, WLED_FS.exists(fileName) ? "r+" : "w+"); From a870474b49900fe5c5ebd6c8ef06a3777feb3241 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 5 Jan 2026 19:26:39 +0100 Subject: [PATCH 2/2] Removed redundant check before closing the file handle --- wled00/file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/file.cpp b/wled00/file.cpp index f65bacb487..ee107c6664 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -38,7 +38,7 @@ void closeFile() { DEBUGFS_PRINT(F("Close -> ")); uint32_t s = millis(); #endif - if (f) f.close(); // only close if we have an open file + f.close(); // "if (f)" check is aleady done inside f.close(), and f cannot be nullptr -> no need for double checking before closing the file handle. DEBUGFS_PRINTF("took %lu ms\n", millis() - s); doCloseFile = false; }