-
Notifications
You must be signed in to change notification settings - Fork 3k
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
littlefs: Fixed issue with cleanup in mount function on error #7851
Conversation
As a part of the v1.6 update, littlefs added proper handling for cleaning up memory in the case of an error during mount. This took care of a memory leak users were seeing. Ironically, it turns out the implementation and user patterns in mbed-os was _relying_ on this memory leak to avoid a double free in the same case of an error during mount. The issue was that a failed mount would leave the LittleFileSystem class in a state where it thought it was mounted, and later it would attempt to unmount the filesystem. With the previous memory leak this would be "ok", and the leaked memory would be freed. But with the fix in v1.6, no memory is leaked, and the incorrect free triggers a hard fault. Fixed to clean up state properly on failed mounts.
Well that's a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Tested the PR and it fixes the problem I was having.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
/morph build |
Build : SUCCESSBuild number : 2861 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2491 |
Test : SUCCESSBuild number : 2624 |
Exporter Build : FAILUREBuild number : 2504 |
LFS_INFO("unmount -> %d", lfs_toerror(err)); | ||
_mutex.unlock(); | ||
return lfs_toerror(err); | ||
if (err && !res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit: !res check is not really needed here Too late :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just kept it for consistency. That way if any code is added between the declaration of res and this line, it won't break anything.
The compiler will optimize it out anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler will optimize it out anyways.
Famous last words
Description
As a part of the v1.6 update (#7713), littlefs added proper handling for cleaning up memory in the case of an error during mount (littlefs-project/littlefs#80). This took care of a memory leak users were seeing. Ironically, it turns out the implementation and user patterns in mbed-os was relying on this memory leak to avoid a double free in the same case of an error during mount.
The issue was that a failed mount would leave the LittleFileSystem class in a state where it thought it was mounted, and later it would attempt to unmount the filesystem. With the previous memory leak this would be "ok", and the leaked memory would be freed. But with the fix in v1.6, no memory is leaked, and the incorrect free triggers a hard fault.
Fixed to clean up state properly on failed mounts.
cc @juhoeskeli, @dannybenor, @deepikabhavnani, @ARMmbed/mbed-os-storage
Pull request type