Pages: [1]   Go Down
Author Topic: Serious bug affects SD.h and String  (Read 1334 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1654
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 28, 2012, 10:02:01 am by fat16lib » Logged

San Diego, California, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Born to be a nerd
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1654
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 01, 2012, 11:33:51 am by fat16lib » Logged

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

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.
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1654
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry PaulS major proof reading error.  

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

Pages: [1]   Go Up
Jump to: