[PATCH] unionfs: fix memory leak when calling krealloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Pekka Enberg <[email protected]>

We must not overwrite the same pointer that is passed to krealloc() 
because it can return NULL without freeing the buffer.  Fixes a memory 
leak introduced by me.

Cc: Josef Sipek <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
---
 fs/unionfs/copyup.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Index: 2.6/fs/unionfs/copyup.c
===================================================================
--- 2.6.orig/fs/unionfs/copyup.c	2007-02-21 14:15:30.000000000 +0200
+++ 2.6/fs/unionfs/copyup.c	2007-02-21 14:16:19.000000000 +0200
@@ -658,11 +658,14 @@
 
 		/* grow path table */
 		if (count == num_dentry) {
-			path = krealloc(path, kmalloc_size * 2, GFP_KERNEL);
-			if (!path) {
+			void *p;
+
+			p = krealloc(path, kmalloc_size * 2, GFP_KERNEL);
+			if (!p) {
 				hidden_dentry = ERR_PTR(-ENOMEM);
 				goto out;
 			}
+			path = p;
 			kmalloc_size = ksize(path);
 			num_dentry = kmalloc_size / sizeof(struct dentry *);
 		}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux