Skip to content

SD begin() end() memory leak #2897

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
cybercatnet opened this issue Jun 17, 2019 · 12 comments · Fixed by #5419
Closed

SD begin() end() memory leak #2897

cybercatnet opened this issue Jun 17, 2019 · 12 comments · Fixed by #5419
Assignees
Milestone

Comments

@cybercatnet
Copy link

cybercatnet commented Jun 17, 2019

Hardware:

Board: ESP32 Dev Module DOIT
Core Installation version: 1.0.1
IDE name: Arduino IDE and Platform.io
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

In my program i have memory leak and i made a simple test.
SD.end() doesnt free all of his heap memory.
My program needs to check if the sd card is connected before touch files, and if is not i need to SD.begin() again in the case of the sd card is again connected.

Sketch:

#include <SPI.h>
#include <SD.h>

void setup() {
Serial.begin(9600);
}

void loop() {
SD.begin(5);
Serial.println((unsigned long)ESP.getFreeHeap());
SD.end();
delay(1000);
}


### Debug Messages:

ESP.getFreeHeap:
249644
249624
249604
249584
249564
249544
249524
249504
249484
249464
249444
249424
249404
249384
249364
249344
249324
249304
249284
249264
249244
249224

@stale
Copy link

stale bot commented Aug 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 17, 2019
@cybercatnet
Copy link
Author

still

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Aug 31, 2019
@atanisoft
Copy link
Collaborator

atanisoft commented Sep 19, 2019

@cybercatnet can you try updating this block to:

    if (card->base_path) {
        err = esp_vfs_fat_unregister_path(card->base_path);
        free(card->base_path);
    }

adding the free line.

@me-no-dev fyi, the card->base_path is being leaked...

@stale
Copy link

stale bot commented Nov 18, 2019

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Nov 18, 2019
@sla256
Copy link

sla256 commented Nov 29, 2019

Seeing the same issue. Similar use case i.e. need to support removing / inserting SD card run time. Observing 20 bytes leaking as well.

@stale
Copy link

stale bot commented Nov 29, 2019

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Nov 29, 2019
@sla256
Copy link

sla256 commented Nov 30, 2019

@cybercatnet can you try updating this block to:

    if (card->base_path) {
        err = esp_vfs_fat_unregister_path(card->base_path);
        free(card->base_path);
    }

adding the free line.

@me-no-dev fyi, the card->base_path is being leaked...

by the way, yes - this change fixes the issue

@stale
Copy link

stale bot commented Jan 29, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jan 29, 2020
@stale
Copy link

stale bot commented Feb 12, 2020

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Feb 12, 2020
@Anx2k
Copy link
Contributor

Anx2k commented Jul 19, 2021

Just an FYI, this leak still happens 1.0.6 and this fix doesn't seem to be incorporated. I manually applied the fix and it appears to resolve the issue for me as well.

@me-no-dev me-no-dev added the Status: Test needed Issue needs testing label Jul 19, 2021
@me-no-dev me-no-dev added this to the 2.0.0 milestone Jul 19, 2021
@SuGlider SuGlider self-assigned this Jul 19, 2021
@VojtechBartoska VojtechBartoska removed the Status: Test needed Issue needs testing label Jul 20, 2021
@VojtechBartoska
Copy link
Contributor

@SuGlider can we close this properly?

@SuGlider
Copy link
Collaborator

Yeah, we can close it, as it was fixed by #5419
Thanks!

@VojtechBartoska VojtechBartoska removed the Status: Stale Issue is stale stage (outdated/stuck) label Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants