From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Andrei Borzenkov <arvidjaar@gmail.com>, Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/2] btrfs-progs: fix a memory leak when starting a transaction on fs with error
Date: Tue, 19 Apr 2022 14:42:24 +0800 [thread overview]
Message-ID: <645e71e0-3f4d-c4ec-d285-fb6546b1bf3e@gmx.com> (raw)
In-Reply-To: <e329a96b-8fe0-0426-f368-f0a1c2eb13b9@gmail.com>
On 2022/4/19 13:09, Andrei Borzenkov wrote:
> On 18.04.2022 16:10, Qu Wenruo wrote:
>> Function btrfs_start_transaction() will allocate the memory
>> unconditionally, but if the fs has an aborted transaction we don't free
>> the allocated memory but return error directly.
>>
>> Fix it by only allocate the new memory after the transaction_aborted
>> check.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> kernel-shared/transaction.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel-shared/transaction.c b/kernel-shared/transaction.c
>> index 0201226678ba..799520a0ef71 100644
>> --- a/kernel-shared/transaction.c
>> +++ b/kernel-shared/transaction.c
>> @@ -25,13 +25,15 @@ struct btrfs_trans_handle* btrfs_start_transaction(struct btrfs_root *root,
>> int num_blocks)
>> {
>> struct btrfs_fs_info *fs_info = root->fs_info;
>> - struct btrfs_trans_handle *h = kzalloc(sizeof(*h), GFP_NOFS);
>> -
>> + struct btrfs_trans_handle *h;
>> +
>> if (fs_info->transaction_aborted)
>> return ERR_PTR(-EROFS);
>>
>> + h = kzalloc(sizeof(*h), GFP_NOFS);
>> if (!h)
>> return ERR_PTR(-ENOMEM);
>> +
>> if (root->commit_root) {
>> error("commit_root already set when starting transaction");
>> kfree(h);
>
> If you are moving allocation of h anyway, why not move it beyond all
> checks and delete redundant kfree(h)?
Good idea.
Thanks,
Qu
next prev parent reply other threads:[~2022-04-19 6:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-18 13:10 [PATCH 0/2] btrfs-progs: bug fixes exposed during delayed chunk items insertion Qu Wenruo
2022-04-18 13:10 ` [PATCH 1/2] btrfs-progs: fix a memory leak when starting a transaction on fs with error Qu Wenruo
2022-04-18 15:26 ` Josef Bacik
2022-04-19 5:09 ` Andrei Borzenkov
2022-04-19 6:42 ` Qu Wenruo [this message]
2022-04-18 13:10 ` [PATCH 2/2] btrfs-progs: fix an error path which can lead to empty device list Qu Wenruo
2022-04-18 15:28 ` Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=645e71e0-3f4d-c4ec-d285-fb6546b1bf3e@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=arvidjaar@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox