* [PATCH] e2fsprogs: fix memory leak in ext2fs_free_generic_bmap()
@ 2011-03-21 10:14 Lukas Czerner
2011-05-08 22:10 ` Ted Ts'o
0 siblings, 1 reply; 3+ messages in thread
From: Lukas Czerner @ 2011-03-21 10:14 UTC (permalink / raw)
To: linux-ext4; +Cc: tytso, Lukas Czerner
In ext2fs_free_generic_bmap() when we are freeing 64-bit bitmap, we do
call free_bmap() to free backend specific bitmap structures, however we
should also free ext2fs_generic_bitmap structure as well. So this commit
fixes that and removes unnecessary assignments.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
lib/ext2fs/gen_bitmap64.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index 8b9e4c5..f343cc7 100644
--- a/lib/ext2fs/gen_bitmap64.c
+++ b/lib/ext2fs/gen_bitmap64.c
@@ -153,11 +153,11 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap)
bmap->bitmap_ops->free_bmap(bmap);
- if (bmap->description) {
+ if (bmap->description)
ext2fs_free_mem(&bmap->description);
- bmap->description = 0;
- }
- bmap->magic = 0;
+
+ ext2fs_free_mem(&bmap);
+ bmap = NULL;
}
errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
--
1.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] e2fsprogs: fix memory leak in ext2fs_free_generic_bmap()
2011-03-21 10:14 [PATCH] e2fsprogs: fix memory leak in ext2fs_free_generic_bmap() Lukas Czerner
@ 2011-05-08 22:10 ` Ted Ts'o
2011-05-09 8:09 ` Lukas Czerner
0 siblings, 1 reply; 3+ messages in thread
From: Ted Ts'o @ 2011-05-08 22:10 UTC (permalink / raw)
To: Lukas Czerner; +Cc: linux-ext4
On Mon, Mar 21, 2011 at 11:14:00AM +0100, Lukas Czerner wrote:
> In ext2fs_free_generic_bmap() when we are freeing 64-bit bitmap, we do
> call free_bmap() to free backend specific bitmap structures, however we
> should also free ext2fs_generic_bitmap structure as well. So this commit
> fixes that and removes unnecessary assignments.
>
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
> lib/ext2fs/gen_bitmap64.c | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
> index 8b9e4c5..f343cc7 100644
> --- a/lib/ext2fs/gen_bitmap64.c
> +++ b/lib/ext2fs/gen_bitmap64.c
> @@ -153,11 +153,11 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap)
>
> bmap->bitmap_ops->free_bmap(bmap);
>
> - if (bmap->description) {
> + if (bmap->description)
> ext2fs_free_mem(&bmap->description);
> - bmap->description = 0;
> - }
> - bmap->magic = 0;
> +
> + ext2fs_free_mem(&bmap);
> + bmap = NULL;
Setting bmap to NULL is pointless since C doesn't have
pass-by-reference ala C++ (i.e., it's not like this function parameter
is declared "ext2fs_generic_bitmap &bmap").
So it's actually a good idea to zap bmap->description, and especially
bmap->magic, since that will allow us to catch attempts to use the
bitmap after we free it.
I'll make the simplification of your patch which just adds the missing
"ext2fs_free_mem(&bmap)" call.
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] e2fsprogs: fix memory leak in ext2fs_free_generic_bmap()
2011-05-08 22:10 ` Ted Ts'o
@ 2011-05-09 8:09 ` Lukas Czerner
0 siblings, 0 replies; 3+ messages in thread
From: Lukas Czerner @ 2011-05-09 8:09 UTC (permalink / raw)
To: Ted Ts'o; +Cc: Lukas Czerner, linux-ext4
On Sun, 8 May 2011, Ted Ts'o wrote:
> On Mon, Mar 21, 2011 at 11:14:00AM +0100, Lukas Czerner wrote:
> > In ext2fs_free_generic_bmap() when we are freeing 64-bit bitmap, we do
> > call free_bmap() to free backend specific bitmap structures, however we
> > should also free ext2fs_generic_bitmap structure as well. So this commit
> > fixes that and removes unnecessary assignments.
> >
> > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> > ---
> > lib/ext2fs/gen_bitmap64.c | 8 ++++----
> > 1 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
> > index 8b9e4c5..f343cc7 100644
> > --- a/lib/ext2fs/gen_bitmap64.c
> > +++ b/lib/ext2fs/gen_bitmap64.c
> > @@ -153,11 +153,11 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap)
> >
> > bmap->bitmap_ops->free_bmap(bmap);
> >
> > - if (bmap->description) {
> > + if (bmap->description)
> > ext2fs_free_mem(&bmap->description);
> > - bmap->description = 0;
> > - }
> > - bmap->magic = 0;
> > +
> > + ext2fs_free_mem(&bmap);
> > + bmap = NULL;
>
> Setting bmap to NULL is pointless since C doesn't have
> pass-by-reference ala C++ (i.e., it's not like this function parameter
> is declared "ext2fs_generic_bitmap &bmap").
>
> So it's actually a good idea to zap bmap->description, and especially
> bmap->magic, since that will allow us to catch attempts to use the
> bitmap after we free it.
>
> I'll make the simplification of your patch which just adds the missing
> "ext2fs_free_mem(&bmap)" call.
>
> - Ted
>
Agh, you're right, sorry about that.
Thanks!
-Lukas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-05-09 8:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-21 10:14 [PATCH] e2fsprogs: fix memory leak in ext2fs_free_generic_bmap() Lukas Czerner
2011-05-08 22:10 ` Ted Ts'o
2011-05-09 8:09 ` Lukas Czerner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).