commit 6b3acd5526a09b222d04893a5861769345edf6e3
Author: Erez_Zadok <[EMAIL PROTECTED]>
Date:   Thu Apr 19 18:40:36 2007 -0400

    bugfix: don't leak resources when copyup fails partially

diff --git a/fs/unionfs/copyup.c b/fs/unionfs/copyup.c
index 2fc73b6..7ebe17d 100644
--- a/fs/unionfs/copyup.c
+++ b/fs/unionfs/copyup.c
@@ -635,7 +635,7 @@ static struct dentry *create_parents_named(struct inode 
*dir,
        int old_kmalloc_size;
        int kmalloc_size;
        int num_dentry;
-       int count;
+       int count = 0;
        int old_bstart;
        int old_bend;
        struct dentry **path = NULL;
@@ -662,7 +662,6 @@ static struct dentry *create_parents_named(struct inode 
*dir,
        /* assume the negative dentry of unionfs as the parent dentry */
        parent_dentry = dentry;
 
-       count = 0;
        /*
         * This loop finds the first parent that exists in the given branch.
         * We start building the directory structure from there.  At the end
@@ -766,6 +765,22 @@ begin:
                                                 hidden_dentry);
                unlock_dir(hidden_parent_dentry);
                if (err) {
+                       struct inode *inode = hidden_dentry->d_inode;
+                       /*
+                        * If we get here, it means that we created a new
+                        * dentry+inode, but copying permissions failed.
+                        * Therefore, we should delete this inode and dput
+                        * the dentry so as not to leave cruft behind.
+                        *
+                        * XXX: call dentry_iput() instead, but then we have
+                        * to export that symbol.
+                        */
+                       if (hidden_dentry->d_op && hidden_dentry->d_op->d_iput)
+                               hidden_dentry->d_op->d_iput(hidden_dentry,
+                                                           inode);
+                       else
+                               iput(inode);
+                       hidden_dentry->d_inode = NULL;
                        dput(hidden_dentry);
                        hidden_dentry = ERR_PTR(err);
                        goto out;
@@ -780,6 +795,10 @@ begin:
        child_dentry = path[--count];
        goto begin;
 out:
+       /* cleanup any leftover locks from the do/while loop above */
+       if (IS_ERR(hidden_dentry))
+               while (count)
+                       unionfs_unlock_dentry(path[count--]);
        kfree(path);
        return hidden_dentry;
 }
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to