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 <jwbo...@fedoraproject.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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to