]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/locks.c
locks: Fix potential OOPS in generic_setlease()
[net-next-2.6.git] / fs / locks.c
index 282b6c11670aa1c2f80239d2524378f8cd7bc2b0..43dbc7f566fa97f829ae4e1448aa4a8fd5ba64df 100644 (file)
@@ -1343,6 +1343,7 @@ int fcntl_getlease(struct file *filp)
 int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
 {
        struct file_lock *fl, **before, **my_before = NULL, *lease;
+       struct file_lock *new_fl = NULL;
        struct dentry *dentry = filp->f_path.dentry;
        struct inode *inode = dentry->d_inode;
        int error, rdlease_count = 0, wrlease_count = 0;
@@ -1369,6 +1370,11 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
                || (atomic_read(&inode->i_count) > 1)))
                goto out;
 
+       error = -ENOMEM;
+       new_fl = locks_alloc_lock();
+       if (new_fl == NULL)
+               goto out;
+
        /*
         * At this point, we know that if there is an exclusive
         * lease on this file, then we hold it on this filp
@@ -1411,18 +1417,15 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
        if (!leases_enable)
                goto out;
 
-       error = -ENOMEM;
-       fl = locks_alloc_lock();
-       if (fl == NULL)
-               goto out;
-
-       locks_copy_lock(fl, lease);
+       locks_copy_lock(new_fl, lease);
+       locks_insert_lock(before, new_fl);
 
-       locks_insert_lock(before, fl);
+       *flp = new_fl;
+       return 0;
 
-       *flp = fl;
-       error = 0;
 out:
+       if (new_fl != NULL)
+               locks_free_lock(new_fl);
        return error;
 }
 EXPORT_SYMBOL(generic_setlease);