public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize.
@ 2008-07-11 10:32 Manish Katiyar
  2008-07-11 18:41 ` Theodore Tso
  2008-07-11 18:46 ` Theodore Tso
  0 siblings, 2 replies; 4+ messages in thread
From: Manish Katiyar @ 2008-07-11 10:32 UTC (permalink / raw)
  To: linux-ext4, Theodore Tso

In function ext2fs_initialize(), if we fail doing
ext2fs_allocate_block_bitmap() or ext2fs_allocate_inode_bitmap() we
directly goto cleanup and
don't free the memory allocated to buf. Below patch fixes it.

===========================================================

Signed-off-by: "Manish Katiyar" <mkatiyar@gmail.com>

---
 lib/ext2fs/initialize.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 011656f..a8375d9 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -105,7 +105,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
 	int		rsv_gdt;
 	int		csum_flag;
 	int		io_flags;
-	char		*buf;
+	char		*buf = 0;
 	char		c;

 	if (!param || !param->s_blocks_count)
@@ -429,6 +429,9 @@ ipg_retry:
 	*ret_fs = fs;
 	return 0;
 cleanup:
+	if (buf) {
+	 ext2fs_free_mem(&buf);
+	}
 	ext2fs_free(fs);
 	return retval;
 }
-- 
1.5.4.3


===========================================================

-- 
Thanks & Regards,
********************************************
Manish Katiyar ( http://mkatiyar.googlepages.com )
3rd Floor, Fair Winds Block
EGL Software Park
Off Intermediate Ring Road
Bangalore 560071, India
***********************************************

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize.
  2008-07-11 10:32 [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize Manish Katiyar
@ 2008-07-11 18:41 ` Theodore Tso
  2008-07-11 18:53   ` Manish Katiyar
  2008-07-11 18:46 ` Theodore Tso
  1 sibling, 1 reply; 4+ messages in thread
From: Theodore Tso @ 2008-07-11 18:41 UTC (permalink / raw)
  To: Manish Katiyar; +Cc: linux-ext4

On Fri, Jul 11, 2008 at 04:02:06PM +0530, Manish Katiyar wrote:
> +	if (buf) {
> +	 ext2fs_free_mem(&buf);
> +	}

I'll fix this up and apply, but in the future, please respect the
surrounding whitespace rules of the source code.  For e2fsprogs that
means (among other things) each level is indented 8 spaces, no curly
braces are needed for single statements, and no white space at the end
of lines.

Thanks,

							- Ted

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize.
  2008-07-11 10:32 [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize Manish Katiyar
  2008-07-11 18:41 ` Theodore Tso
@ 2008-07-11 18:46 ` Theodore Tso
  1 sibling, 0 replies; 4+ messages in thread
From: Theodore Tso @ 2008-07-11 18:46 UTC (permalink / raw)
  To: Manish Katiyar; +Cc: linux-ext4

Here's how the patch was applied; please note the style fixes I made
in the code and in the patch comments.

       	       	     	 	  	      - Ted

>From adc4e77d89d9a423c3fbe6457676b020c9ad3a64 Mon Sep 17 00:00:00 2001
From: Manish Katiyar <mkatiyar@gmail.com>
Date: Fri, 11 Jul 2008 14:42:57 -0400
Subject: [PATCH] libext2fs: fix potential memory leak in ext2fs_initialize()

If we fail doing ext2fs_allocate_block_bitmap() or
ext2fs_allocate_inode_bitmap() we directly goto cleanup and don't free
the memory allocated to buf.

Signed-off-by: "Manish Katiyar" <mkatiyar@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 lib/ext2fs/initialize.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 011656f..e9bfe49 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -105,7 +105,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
 	int		rsv_gdt;
 	int		csum_flag;
 	int		io_flags;
-	char		*buf;
+	char		*buf = 0;
 	char		c;
 
 	if (!param || !param->s_blocks_count)
@@ -429,6 +429,8 @@ ipg_retry:
 	*ret_fs = fs;
 	return 0;
 cleanup:
+	if (buf)
+		free(buf);
 	ext2fs_free(fs);
 	return retval;
 }
-- 
1.5.6.1.205.ge2c7.dirty


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize.
  2008-07-11 18:41 ` Theodore Tso
@ 2008-07-11 18:53   ` Manish Katiyar
  0 siblings, 0 replies; 4+ messages in thread
From: Manish Katiyar @ 2008-07-11 18:53 UTC (permalink / raw)
  To: Theodore Tso, linux-ext4

On Sat, Jul 12, 2008 at 12:11 AM, Theodore Tso <tytso@mit.edu> wrote:
> On Fri, Jul 11, 2008 at 04:02:06PM +0530, Manish Katiyar wrote:
>> +     if (buf) {
>> +      ext2fs_free_mem(&buf);
>> +     }
>
> I'll fix this up and apply, but in the future, please respect the
> surrounding whitespace rules of the source code.  For e2fsprogs that
> means (among other things) each level is indented 8 spaces, no curly
> braces are needed for single statements, and no white space at the end
> of lines.

Thanks a lot Ted,
 I will keep that in mind in future. I am not sure from where did
those white spaces came, I don't have them in my git log.....and curly
braces for single statements were because I copied the style from
below line in ext2fs_free() .... perhaps a bad example which I chose
to follow :-(

	if (fs->io) {
		io_channel_close(fs->io);
	}

Thanks -


>
> Thanks,
>
>                                                        - Ted
>



-- 
Thanks & Regards,
********************************************
Manish Katiyar ( http://mkatiyar.googlepages.com )
3rd Floor, Fair Winds Block
EGL Software Park
Off Intermediate Ring Road
Bangalore 560071, India
***********************************************

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-11 18:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-11 10:32 [PATCH] e2fsprogs : Fix memory leak in ext2fs_initialize Manish Katiyar
2008-07-11 18:41 ` Theodore Tso
2008-07-11 18:53   ` Manish Katiyar
2008-07-11 18:46 ` Theodore Tso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox