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:
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 theFile::File(void)
constructor to notmalloc()
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: