From 236e434296ba5f5c3fa740d1d97af4385d817bc9 Mon Sep 17 00:00:00 2001 From: Chad Attermann Date: Fri, 12 Jul 2024 13:18:40 -0600 Subject: [PATCH] Additionally clearing pointers just in case Clearing `_file` and `_dir` pointers after freeing on failure to open just in case close() is later called. To elaborate, the `_file` and `_dir` pointers are normally freed and cleared by _close(), but when a failure occurs upon opening, these pointers were being left orphaned since calling close() after failure to open doesn't make much sense, and indeed caused serious issues within lfs. --- libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp b/libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp index 3091f477e..43ed2d962 100644 --- a/libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp +++ b/libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp @@ -68,6 +68,7 @@ bool File::_open_file (char const *filepath, uint8_t mode) PRINT_LFS_ERR(rc); // free memory rtos_free(_file); + _file = NULL; return false; } @@ -93,6 +94,7 @@ bool File::_open_dir (char const *filepath) PRINT_LFS_ERR(rc); // free memory rtos_free(_dir); + _dir = NULL; return false; }