Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector()
Date: Tue, 4 Jun 2024 14:07:42 +0930	[thread overview]
Message-ID: <cc455e1b-7ed1-49ad-b512-cc556f57b0a4@suse.com> (raw)
In-Reply-To: <ebd4d57790941a9c1edef52e09ce0bb4838ab27d.1717474840.git.wqu@suse.com>



在 2024/6/4 13:51, Qu Wenruo 写道:
> ASAN build (make D=asan) would cause memory leak for
> btrfs-corrupt-block inside debug_corrupt_sector().
> 
> This can be reproduced by fsck/013 test case.
> 
> The cause is pretty simple, we just malloc a sector and forgot to free
> it.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Missing the issue tag:

Issue: #806

That's already fixed in my github repo and would create a pull request 
for it.

Thanks,
Qu
> ---
>   btrfs-corrupt-block.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
> index 124597333771..e88319891910 100644
> --- a/btrfs-corrupt-block.c
> +++ b/btrfs-corrupt-block.c
> @@ -70,7 +70,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
>   			if (ret < 0) {
>   				errno = -ret;
>   				error("cannot read bytenr %llu: %m", logical);
> -				return ret;
> +				goto out;
>   			}
>   			printf("corrupting %llu copy %d\n", logical, mirror_num);
>   			memset(buf, 0, sectorsize);
> @@ -78,7 +78,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
>   			if (ret < 0) {
>   				errno = -ret;
>   				error("cannot write bytenr %llu: %m", logical);
> -				return ret;
> +				goto out;
>   			}
>   		}
>   
> @@ -90,7 +90,8 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
>   		if (mirror_num > num_copies)
>   			break;
>   	}
> -
> +out:
> +	free(buf);
>   	return 0;
>   }
>   

  reply	other threads:[~2024-06-04  4:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04  4:21 [PATCH] btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector() Qu Wenruo
2024-06-04  4:37 ` Qu Wenruo [this message]
2024-06-04 15:55 ` 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=cc455e1b-7ed1-49ad-b512-cc556f57b0a4@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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