Pages: [1]   Go Down
Author Topic: SD Library Potential Memory Leak  (Read 1223 times)
0 Members and 1 Guest are viewing this topic.
Virginia, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was looking through the SD libarary and I found what looks like a potential memory leak.  When a file is opened a malloc() is performed to get memory.  When a file is closed the memory is freed.

But... If the file object is destroyed before the file is closed, the memory is never freed.

My suggestion would be to modify the destructor as follows:

Old code:
Code:
File::~File(void) {
  //  Serial.print("Deleted file object");
}

New code:
Code:
File::~File(void) {
  close();
  //  Serial.print("Deleted file object");
}



Does this seek correct or am I way off here?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does this seek correct or am I way off here?
Yes, it is correct. No, you are not way off. Not even a little off.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Jgoulder,

I reported it here - http://code.google.com/p/arduino/issues/detail?id=814&thanks=814&ts=1329044927 -
« Last Edit: February 12, 2012, 06:09:30 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: