linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][resend] Don't leak memory in failure paths of gfs2_acl_get()
@ 2011-03-21 19:29 Jesper Juhl
  0 siblings, 0 replies; only message in thread
From: Jesper Juhl @ 2011-03-21 19:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: Steven Whitehouse, cluster-devel

In fs/gfs2/acl.c::gfs2_acl_get() we may leak memory in failure scenarios.
gfs2_xattr_acl_get() may return <=0 after having dynamically allocated 
memory for its last argument ('data' in the gfs2_acl_get() caller) and in 
that case the caller leaks the memory.
This patch initializes 'data' to NULL and calls kfree() on 'data' in the 
failure paths. This ensures that we always free the memory on failure or 
that we just call kfree(NULL) on failures where no memory has actually 
been allocated yet.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 acl.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

 Patch against Linus' tree as of right now.
 Compile tested only.

diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index cbc0715..7d231fb 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -42,7 +42,7 @@ static struct posix_acl *gfs2_acl_get(struct gfs2_inode *ip, int type)
 {
 	struct posix_acl *acl;
 	const char *name;
-	char *data;
+	char *data = NULL;
 	int len;
 
 	if (!ip->i_eattr)
@@ -57,10 +57,14 @@ static struct posix_acl *gfs2_acl_get(struct gfs2_inode *ip, int type)
 		return ERR_PTR(-EINVAL);
 
 	len = gfs2_xattr_acl_get(ip, name, &data);
-	if (len < 0)
+	if (len < 0) {
+		kfree(data);
 		return ERR_PTR(len);
-	if (len == 0)
+	}
+	if (len == 0) {
+		kfree(data);
 		return NULL;
+	}
 
 	acl = posix_acl_from_xattr(data, len);
 	kfree(data);


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-21 19:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-21 19:29 [PATCH][resend] Don't leak memory in failure paths of gfs2_acl_get() Jesper Juhl

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).