Skip to content

Commit

Permalink
Additionally clearing pointers just in case
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
attermann committed Jul 12, 2024
1 parent 1ce5cf1 commit 236e434
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -93,6 +94,7 @@ bool File::_open_dir (char const *filepath)
PRINT_LFS_ERR(rc);
// free memory
rtos_free(_dir);
_dir = NULL;
return false;
}

Expand Down

0 comments on commit 236e434

Please sign in to comment.