* [PATCH] btrfs : fix memory leak in add_block_entry
@ 2020-07-07 13:29 trix
2020-07-14 14:10 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2020-07-07 13:29 UTC (permalink / raw)
To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Tom Rix
From: Tom Rix <trix@redhat.com>
clang static analysis flags this error
fs/btrfs/ref-verify.c:290:3: warning: Potential leak of memory pointed to by 're' [unix.Malloc]
kfree(be);
^~~~~
The problem is in this block of code
if (root_objectid) {
struct root_entry *exist_re;
exist_re = insert_root_entry(&exist->roots, re);
if (exist_re)
kfree(re);
}
There is no 'else' block freeing when root_objectid == 0
So add an 'else'
Fixes: fd708b81d972 ("Btrfs: add a extent ref verify tool")
Signed-off-by: Tom Rix <trix@redhat.com>
---
fs/btrfs/ref-verify.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index af92525dbb16..7f03dbe5b609 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -286,6 +286,8 @@ static struct block_entry *add_block_entry(struct btrfs_fs_info *fs_info,
exist_re = insert_root_entry(&exist->roots, re);
if (exist_re)
kfree(re);
+ } else {
+ kfree(re);
}
kfree(be);
return exist;
--
2.18.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs : fix memory leak in add_block_entry
2020-07-07 13:29 [PATCH] btrfs : fix memory leak in add_block_entry trix
@ 2020-07-14 14:10 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2020-07-14 14:10 UTC (permalink / raw)
To: trix; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel
On Tue, Jul 07, 2020 at 06:29:08AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> clang static analysis flags this error
>
> fs/btrfs/ref-verify.c:290:3: warning: Potential leak of memory pointed to by 're' [unix.Malloc]
> kfree(be);
> ^~~~~
> The problem is in this block of code
>
> if (root_objectid) {
> struct root_entry *exist_re;
>
> exist_re = insert_root_entry(&exist->roots, re);
> if (exist_re)
> kfree(re);
> }
>
> There is no 'else' block freeing when root_objectid == 0
>
> So add an 'else'
>
> Fixes: fd708b81d972 ("Btrfs: add a extent ref verify tool")
>
> Signed-off-by: Tom Rix <trix@redhat.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-14 14:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-07 13:29 [PATCH] btrfs : fix memory leak in add_block_entry trix
2020-07-14 14:10 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox