diff options
author | David Sterba <dsterba@suse.com> | 2024-04-04 00:55:47 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-04-18 19:16:15 +0200 |
commit | 844caf8639826ed4ddc6dc7b3ba30bd19f9b21d8 (patch) | |
tree | 237780562b1c16ff26531fefe4763d5482e9b081 | |
parent | 2bdb838d549bb81cc441c9b0a834f0143dd9c1ce (diff) | |
download | btrfs-progs-844caf8639826ed4ddc6dc7b3ba30bd19f9b21d8.tar.gz |
btrfs-progs: fix double free on error in read_raid56()
Reported by 'gcc -fanalyzer':
kernel-shared/extent_io.c: In function ‘read_raid56’:
./include/kerncompat.h:393:18: warning: dereference of NULL ‘pointers’ [CWE-476] [-Wanalyzer-null-dereference]
After allocation of the pointers array fails it's dereferenced in the
exit block. We can return immediately instead.
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | kernel-shared/extent_io.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c index ee19430d..e62ca63c 100644 --- a/kernel-shared/extent_io.c +++ b/kernel-shared/extent_io.c @@ -339,10 +339,9 @@ static int read_raid56(struct btrfs_fs_info *fs_info, void *buf, u64 logical, ASSERT(len <= BTRFS_STRIPE_LEN); pointers = calloc(num_stripes, sizeof(void *)); - if (!pointers) { - ret = -ENOMEM; - goto out; - } + if (!pointers) + return -ENOMEM; + /* Allocate memory for the full stripe */ for (i = 0; i < num_stripes; i++) { pointers[i] = kmalloc(BTRFS_STRIPE_LEN, GFP_KERNEL); |