]> www.infradead.org Git - linux.git/commitdiff
jbd2: avoid memleak in jbd2_journal_write_metadata_buffer
authorKemeng Shi <shikemeng@huaweicloud.com>
Tue, 14 May 2024 11:24:30 +0000 (19:24 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 27 Jun 2024 14:20:26 +0000 (10:20 -0400)
The new_bh is from alloc_buffer_head, we should call free_buffer_head to
free it in error case.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20240514112438.1269037-2-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/journal.c

index 03c4b9214f564a311bd1dd028abe2a7fb6aa2ee1..5ad255ffb289c78ec232d198ad404eed08bd33f6 100644 (file)
@@ -399,6 +399,7 @@ repeat:
                tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
                if (!tmp) {
                        brelse(new_bh);
+                       free_buffer_head(new_bh);
                        return -ENOMEM;
                }
                spin_lock(&jh_in->b_state_lock);