Go Down

Topic: Serious bug affects SD.h and String (Read 1 time) previous topic - next topic

fat16lib

Jul 28, 2012, 04:59 pm Last Edit: Jul 28, 2012, 05:02 pm by fat16lib Reason: 1
There is a serious bug in 1.01 and some earlier Arduino versions that may cause crashes when you use SD.h and/or String.

The bug is in the function free() which deallocates memory.  

SD.h calls free() when you close a file.  

String may call free() when the size of a string changes or in destructors.

Frequent opening and closing of files, especially multiple file, may cause a crash in SD.h.

See this for an example of the String problem http://arduino.cc/forum/index.php/topic,115552.0.html.

The above topic also describes two fixes for the free() bug.

The SdFat library does not call free().  The bug is in the Arduino SD.h wrapper for SdFat.

saunj

Yes, String does not do a good job of recovering memory. If in loop(0, the free memory reduces each cycle until it crashes. However, the File library, included in SD, is OK to create an instance for each write, so that each record can open and close. My problem is with SD's SRAM usage, needing 400 bytes free before making a record. In my latest project (see http://projects.worsleyassociates.com/ArdurinoLogger/index.html?) I had to use PROGMEM to cut my SRAM footprint. Since I had to write a custom LCD class anyway,(because I used a shift register) I put the excess code to display a string from the program memory in a method.

fat16lib

#2
Jul 31, 2012, 11:12 pm Last Edit: Aug 01, 2012, 06:33 pm by fat16lib Reason: 1
It's not a matter of doing a good job.  

The core Arduino software has a serious bug in dynamic memory allocation so any library that uses dynamic memory may crash even if very little memory is used.

The bug involves how the free list is maintained. So SD or String can suddenly crash with very little memory in use.

PaulS

Quote
So SD or String can't expectantly crash with very little memory in use.

They can't? I thought that was what the bug caused to happen.

fat16lib

Sorry PaulS major proof reading error.  

free() can really jumble the free list and then sometime later this mess leads to a crash.

Go Up