nfsd: Fix memory leak in nfsd_getxattr
authorKrishna Kumar <krkumar2@in.ibm.com>
Wed, 22 Oct 2008 09:18:36 +0000 (14:48 +0530)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Wed, 22 Oct 2008 18:00:45 +0000 (14:00 -0400)
Fix a memory leak in nfsd_getxattr. nfsd_getxattr should free up memory
that it allocated if vfs_getxattr fails.

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
fs/nfsd/vfs.c

index aa1d0d6..9609eb5 100644 (file)
@@ -410,6 +410,7 @@ out_nfserr:
 static ssize_t nfsd_getxattr(struct dentry *dentry, char *key, void **buf)
 {
        ssize_t buflen;
+       ssize_t ret;
 
        buflen = vfs_getxattr(dentry, key, NULL, 0);
        if (buflen <= 0)
@@ -419,7 +420,10 @@ static ssize_t nfsd_getxattr(struct dentry *dentry, char *key, void **buf)
        if (!*buf)
                return -ENOMEM;
 
-       return vfs_getxattr(dentry, key, *buf, buflen);
+       ret = vfs_getxattr(dentry, key, *buf, buflen);
+       if (ret < 0)
+               kfree(*buf);
+       return ret;
 }
 #endif