[PATCH] CacheFiles: Fix memory leak in cachefiles_check_auxdata error paths

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

 



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@xxxxxxxxxxxxxxxxx>
---
 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

--
Linux-cachefs mailing list
Linux-cachefs@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/linux-cachefs




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]
  Powered by Linux