Skip to content

memory leak in SD library - IDE 1.0 [imported] #814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cmaglie opened this issue Nov 15, 2012 · 5 comments · Fixed by #1383
Closed

memory leak in SD library - IDE 1.0 [imported] #814

cmaglie opened this issue Nov 15, 2012 · 5 comments · Fixed by #1383
Assignees
Labels
Library: SD The SD Arduino library

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 814 moved from a Google Code project.
Added by 2012-02-12T11:08:47.000Z by rob.till...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

JGoulder reported:

When a file is opened a malloc() is performed to get memory. When a file is closed the memory is freed. If the file object is destroyed before the file is closed, the memory is never freed.

Existing code:

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

JGoulder also proposed a fix:

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

@bjelojac
Copy link
Contributor

This is still a problem, and a nasty one. Can this fix PLEASE get pulled into trunk? I've verified the fix, and have to manually fix it every Arduino release.

bjelojac added a commit to bjelojac/Arduino that referenced this issue Apr 25, 2013
File isn't closed before being released, it leaks. This test has been verified and tested many times.
ffissore added a commit that referenced this issue Oct 9, 2013
@ffissore
Copy link
Contributor

@bjelojac after having applied your patch, "listfiles" example does work anymore. Can you give it a spin and confirm?

ffissore pushed a commit that referenced this issue Oct 15, 2013
@ffissore
Copy link
Contributor

I've removed the File destructor. The safest way to free memory allocated by a File object is to call its close() method.

listfiles example was no longer working because to the moment the compiler chooses to call an object destructor. In SD.cpp openNextFile method a new File is returned. However its destructor is called right after the object is created but before it is returned, leading openNextFile method to always return closed File instances.

Removing the destructor enforces the role of the close() method, which must be called to free allocated memory and resources.

@ffissore
Copy link
Contributor

Sorry wrong button. Please close the issue if you agree with previous comment or let's discuss the matter further

@ffissore ffissore reopened this Oct 15, 2013
cmaglie added a commit that referenced this issue Oct 17, 2013
oriregev pushed a commit to oriregev/Arduino that referenced this issue Dec 20, 2013
File isn't closed before being released, it leaks. This test has been verified and tested many times.
oriregev pushed a commit to oriregev/Arduino that referenced this issue Dec 20, 2013
oriregev pushed a commit to oriregev/Arduino that referenced this issue Dec 20, 2013
@ffissore ffissore added the New label Feb 27, 2014
@cmaglie cmaglie removed the New label Feb 27, 2014
@sandeepmistry
Copy link
Contributor

Closing this, as there were no further discussions after Oct. 15, 2013.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Library: SD The SD Arduino library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants