Go Down

Topic: SD Library Potential Memory Leak (Read 1 time) previous topic - next topic

jgoulder

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: [Select]

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


New code:
Code: [Select]

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




Does this seek correct or am I way off here?

PaulS

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.

robtillaart

#2
Feb 12, 2012, 11:57 am Last Edit: Feb 12, 2012, 12:09 pm by robtillaart Reason: 1
Rob Tillaart

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

Go Up