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

Memory leak in vfs_fat_sdmmc#esp_vfs_fat_sdmmc_mount (IDFGH-1969) #4165

Closed
BeckerMarkus opened this issue Oct 5, 2019 · 1 comment
Closed
Assignees

Comments

@BeckerMarkus
Copy link
Contributor

A small amount of memory allocated in esp_vfs_fat_sdmmc_mount will never be released, if the proc errors out via goto fail.

In esp_vfs_fat_sdmmc_mount, s_base_path = strdup(base_path) allocates memory. Then, if there is an error, the function performs a goto fail pattern, where all previously allocated resources should be released - it just misses s_base_path.

While the leak is small, there are scenarios where esp_vfs_fat_sdmmc_mount gets called multiple times and fails because the user inserted an invalid SD card
or the app uses a poor mans strategy to query for a plugged SD card by polling esp_vfs_fat_sdmmc_mount.

And easy to fix obviously:

--- /tmp/meld-tmpl80zweco
+++ /home/esp32/esp/esp-idf/components/fatfs/src/vfs_fat_sdmmc.c
@@ -158,6 +158,8 @@
     ff_diskio_unregister(pdrv);
     free(s_card);
     s_card = NULL;
+    free( s_base_path);
+    s_base_path = NULL;
     return err;
 }

Best,
Markus

@github-actions github-actions bot changed the title Memory leak in vfs_fat_sdmmc#esp_vfs_fat_sdmmc_mount Memory leak in vfs_fat_sdmmc#esp_vfs_fat_sdmmc_mount (IDFGH-1969) Oct 5, 2019
@dobairoland
Copy link
Collaborator

Thank you @BeckerMarkus for reporting this and giving a hint to fix it. We'll look into this...

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

No branches or pull requests

2 participants