From c2c2ce6b97d96ab1e13008392188e5a0360dd85a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 9 Apr 2019 17:41:26 -0500 Subject: [PATCH] Fixed issue with handling block device errors in lfs_file_sync lfs_file_sync was not correctly setting the LFS_F_ERRED flag. Fortunately this is a relatively easy fix. LFS_F_ERRED prevents further issues from occuring when cleaning up resources with lfs_file_close. found by TheLoneWolfling --- lfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lfs.c b/lfs.c index 8ef03e2..639e016 100644 --- a/lfs.c +++ b/lfs.c @@ -2578,6 +2578,7 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { while (true) { int err = lfs_file_flush(lfs, file); if (err) { + file->flags |= LFS_F_ERRED; return err; } @@ -2613,6 +2614,7 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { if (err == LFS_ERR_NOSPC && (file->flags & LFS_F_INLINE)) { goto relocate; } + file->flags |= LFS_F_ERRED; return err; } @@ -2626,6 +2628,7 @@ relocate: file->off = file->pos; err = lfs_file_relocate(lfs, file); if (err) { + file->flags |= LFS_F_ERRED; return err; } }