btrfs-progs: Do proper error handling in add_cache_extent()
PATCH 1/1 btrfs-progs: Do proper error handling in add_cache_extent()
If we have memory allocation failure in add_cache_extent(), it will simply exit with one error message.
That's definitely not proper, especially when all but one call sites have handled the error.
This patch will return -ENOMEM for add_cache_extent(), and fix the only call site which doesn't handle error from it.
Signed-off-by Qu Wenruo <[email protected]>
--- check/main.c | 12 +++++++++++- extent-cache.c | 6 ++---- 2 files changed, 13 insertions(+), 5 deletions(-)
check/main.c +11 -1
@@ -4924,7 +4924,17 @@ static int add_pending(struct cache_tree *pending, ret =add_cache_extent (seen, bytenr, size);if (ret)return ret; -add_cache_extent (pending, bytenr, size); + ret =add_cache_extent (pending, bytenr, size); +if (ret) { +struct cache_extent *entry; + + entry =lookup_cache_extent (seen, bytenr, size); +if (entry && entry->start == bytenr && entry->size == size) { +remove_cache_extent (seen, entry); +free (entry); + } +return ret; + }return 0 ; }
extent-cache.c +2 -4
@@ -111,10 +111,8 @@ int add_cache_extent(struct cache_tree *tree, u64 start, u64 size)struct cache_extent *pe =alloc_cache_extent (start, size);int ret; -if (!pe) { -fprintf (stderr,"memory allocation failed\n" ); -exit (1 ); - } +if (!pe) +return -ENOMEM ; ret =insert_cache_extent (tree, pe);if (ret)
Signature · 1 line
2.26.0
Quoted 10 lines · Qu Wenruo
If we have memory allocation failure in
add_cache_extent(), it will simply exit with one error message.That's definitely not proper, especially when all but one call sites have handled the error.
This patch will return
-ENOMEMforadd_cache_extent(), and fix the only call site which doesn't handle error from it.Signed-off-by Qu Wenruo <[email protected]>
Added to devel, thanks.