Skip to content
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

Fixes leak on creation/destruction of temporary objects #92

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mrjimenez
Copy link

When temporary File() objects are created, the programmer is not able to call close(). That made the SD library leak memory. To fix it properly, not only must we supply a destructor calling close(), but we must also not use a pointer to a SdFile, because the pointer gets copied to other objects (e.g. on a call to open()), and when this temporary object gets destructed, the buffer of the newly created object gets freed. This pull request fixes this issue.

The SD library was leaking memory due to the lack of destructor. There
were subtle situations where temporary objects were created and
destructed and the programmer had no chance to call close(). So, we
need a destructor that calls close(). But to do so, we also need to
change the pointer to SdFile to an actual SdFile object, otherwise the
pointer will be copied and when one object is freed, the other object
will loose its buffer too.
@mrjimenez
Copy link
Author

It seems like you CI script has a problem:

$ wget --directory-prefix="${HOME}/astyle" https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf
--2021-04-10 04:48:14--  https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2021-04-10 04:48:14 ERROR 404: Not Found.
The command "wget --directory-prefix="${HOME}/astyle" https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf" failed and exited with 8 during .
Your build has been stopped.

@per1234
Copy link
Contributor

per1234 commented Apr 11, 2021

Hi @mrjimenez. You're right. The Travis CI configuration became outdated and this part of it was failing anyway due to previous contributors disregarding the results. Since it was planned for replacement, we didn't bother to update it. It will be resolved by #93

I the meantime, you can feel free to disregard the failure of this formatting check job. It's only the other jobs that matter, and I can see that they are all passing. Thanks so much for your contribution to the project!

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants