[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20130910141932.GA30716@hansolo.jdub.homelinux.org>
Date: Tue, 10 Sep 2013 10:19:33 -0400
From: Josh Boyer <jwboyer@...hat.com>
To: David Howells <dhowells@...hat.com>
Cc: linux-cachefs@...hat.com, linux-kernel@...r.kernel.org
Subject: [PATCH] CacheFiles: Fix memory leak in cachefiles_check_auxdata
error paths
We kmalloc auxbuf but fail to kfree it if we get errors in various places.
Rework the error paths to avoid the resource leak.
Signed-off-by: Josh Boyer <jwboyer@...oraproject.org>
---
fs/cachefiles/xattr.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index 34c88b8..f929ab6 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -176,20 +176,28 @@ int cachefiles_check_auxdata(struct cachefiles_object *object)
auxbuf->len = vfs_getxattr(dentry, cachefiles_xattr_cache,
&auxbuf->type, 512 + 1);
- if (auxbuf->len < 1)
- return -ESTALE;
+ if (auxbuf->len < 1) {
+ ret = -ESTALE;
+ goto error;
+ }
- if (auxbuf->type != object->fscache.cookie->def->type)
- return -ESTALE;
+ if (auxbuf->type != object->fscache.cookie->def->type) {
+ ret = -ESTALE;
+ goto error;
+ }
dlen = auxbuf->len - 1;
ret = fscache_check_aux(&object->fscache, &auxbuf->data, dlen);
- kfree(auxbuf);
- if (ret != FSCACHE_CHECKAUX_OKAY)
- return -ESTALE;
+ if (ret != FSCACHE_CHECKAUX_OKAY) {
+ ret = -ESTALE;
+ goto error;
+ }
- return 0;
+ ret = 0;
+error:
+ kfree(auxbuf);
+ return ret;
}
/*
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists