diff mbox series

[1/9] jbd2: avoid memleak in jbd2_journal_write_metadata_buffer

Message ID 20240506141801.1165315-2-shikemeng@huaweicloud.com
State Superseded
Headers show
Series A fix and some cleanups to jbd2 | expand

Commit Message

Kemeng Shi May 6, 2024, 2:17 p.m. UTC
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>
---
 fs/jbd2/journal.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Zhang Yi May 6, 2024, 2:42 p.m. UTC | #1
On 2024/5/6 22:17, Kemeng Shi wrote:
> The new_bh is from alloc_buffer_head, we should call free_buffer_head to
> free it in error case.

Oh, yeah, this is a separate bh, so it should be freed explicitly, it
looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/jbd2/journal.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index b6c114c11b97..207b24e12ce9 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -399,6 +399,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
>  		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);
>
Jan Kara May 12, 2024, 10:09 a.m. UTC | #2
On Mon 06-05-24 22:17:53, Kemeng Shi wrote:
> 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>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/jbd2/journal.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index b6c114c11b97..207b24e12ce9 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -399,6 +399,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
>  		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);
> -- 
> 2.30.0
>
diff mbox series

Patch

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index b6c114c11b97..207b24e12ce9 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -399,6 +399,7 @@  int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
 		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);