stm32duino / STM32SD

Enables reading and writing on SD card using SD card slot of the STM32 Board.
157 stars 23 forks source link

Fix RAM losses when creating files #31

Closed AnHardt closed 3 years ago

AnHardt commented 4 years ago

File::File used to allocate RAM what was not freed when destroying the File object. Adding a dedicated destructor war not enough to fix. It would also need copy- and move-constructors.

Instead of that i went an other way.

Removed the File::FILE(const char* name) constructor. Changed the File::File(void) constructor to not malloc() any RAM.

Unified and changed the SDClass::open() methods. Removed the open method without mode parameter. Instead gave a default mode to the method with a mode parameter. Now open() has the complete control over memory allocation. When it is not able to open a file no memory in left allocated.

Advantage: A created File that was not opened or was not able to be opened has not to be closed anymore to avoid memory losses. Only a successfully opened file has to be closed.

Fixing the memory leak, not only working around #24: