]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] kNFSd: Make sure export_open cleans up on failure.
authorNeil Brown <neilb@cse.unsw.edu.au>
Wed, 30 Oct 2002 08:24:22 +0000 (00:24 -0800)
committerLinus Torvalds <torvalds@penguin.transmeta.com>
Wed, 30 Oct 2002 08:24:22 +0000 (00:24 -0800)
Currently if the kmalloc in exports_open fails,
the seq_file isn't seq_released.

We now do the kmalloc first, and make sure to kfree
if seq_open fails.

fs/nfsd/nfsctl.c

index 85ca18fe1b5086a64883080384ef2af83ee3e748..4d208cbaa5d9d304ed3d9ceba72398ccf8cba501 100644 (file)
@@ -127,14 +127,16 @@ extern struct seq_operations nfs_exports_op;
 static int exports_open(struct inode *inode, struct file *file)
 {
        int res;
+       char *namebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+       if (namebuf == NULL)
+               return -ENOMEM;
+
        res = seq_open(file, &nfs_exports_op);
-       if (!res) {
-               char *namebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
-               if (namebuf == NULL)
-                       res = -ENOMEM;
-               else
-                       ((struct seq_file *)file->private_data)->private = namebuf;
-       }
+       if (res)
+               kfree(namebuf);
+       else
+               ((struct seq_file *)file->private_data)->private = namebuf;
+
        return res;
 }
 static int exports_release(struct inode *inode, struct file *file)