subsys/fs: Fix fs_close on closed file causing NULL dereference

If fs_close gets invoked on closed file (e.g. double close) it would
cause NULL dereference and system crash. Instead now it will just
return with success, as the file is already closed anyway.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2020-07-03 09:23:34 +00:00 committed by Anas Nashif
commit 54492c2748

View file

@ -109,6 +109,10 @@ int fs_close(struct fs_file_t *zfp)
{
int rc = -EINVAL;
if (zfp->mp == NULL) {
return 0;
}
if (zfp->mp->fs->close != NULL) {
rc = zfp->mp->fs->close(zfp);
if (rc < 0) {