bcachefs: fix the memory leak in exception case
authorHongbo Li <lihongbo22@huawei.com>
Tue, 24 Sep 2024 01:41:46 +0000 (09:41 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 28 Sep 2024 01:46:34 +0000 (21:46 -0400)
The pointer clean points the memory allocated by kmemdup, when the
return value of bch2_sb_clean_validate_late is not zero. The memory
pointed by clean is leaked. So we should free it in this case.

Fixes: a37ad1a3aba9 ("bcachefs: sb-clean.c")
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/sb-clean.c

index 025848a9c4c03dc14a5dcda55494a7b6ef8d00d6..0052752818045b0c7ed6f02956f912010461fb2a 100644 (file)
@@ -167,6 +167,7 @@ struct bch_sb_field_clean *bch2_read_superblock_clean(struct bch_fs *c)
 
        ret = bch2_sb_clean_validate_late(c, clean, READ);
        if (ret) {
+               kfree(clean);
                mutex_unlock(&c->sb_lock);
                return ERR_PTR(ret);
        }