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

littlefs: Fixed issue with cleanup in mount function on error #7851

Merged
merged 2 commits into from
Aug 23, 2018

Conversation

geky
Copy link
Contributor

@geky geky commented Aug 21, 2018

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

[ ] Fix
[x] Fix for unreleased feature
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Breaking change

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.
@cmonr
Copy link
Contributor

cmonr commented Aug 22, 2018

[x] Fix dependent on unreleased feature

Well that's a new one.

Copy link
Contributor

@juhoeskeli juhoeskeli left a 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.

Copy link
Contributor

@davidsaada davidsaada left a 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.

Copy link
Contributor

@OPpuolitaival OPpuolitaival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 22, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 22, 2018

Build : SUCCESS

Build number : 2861
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7851/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 22, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 23, 2018

@0xc0170 0xc0170 merged commit 603c4f9 into ARMmbed:master Aug 23, 2018
@mbed-ci
Copy link

mbed-ci commented Aug 23, 2018

LFS_INFO("unmount -> %d", lfs_toerror(err));
_mutex.unlock();
return lfs_toerror(err);
if (err && !res) {
Copy link

@deepikabhavnani deepikabhavnani Aug 23, 2018

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 :-)

Copy link
Contributor Author

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.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants