jbd2: avoid memleak in jbd2_journal_write_metadata_buffer

[ Upstream commit cc102aa24638b90e04364d64e4f58a1fa91a1976 ]

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 <[email protected]>
Reviewed-by: Zhang Yi <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
Kemeng Shi 2024-05-14 19:24:30 +08:00 • committed by Greg Kroah-Hartman
commit 969d683bfe

View file

@ -408,6 +408,7 @@ repeat:
tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
if (!tmp) {
brelse(new_bh);
free_buffer_head(new_bh);
return -ENOMEM;
}
jbd_lock_bh_state(bh_in);