nfs: plug memory leak when ->prepare_layoutcommit fails
authorJeff Layton <jlayton@poochiereds.net>
Fri, 10 Jul 2015 19:58:42 +0000 (15:58 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 28 Jul 2015 13:07:02 +0000 (09:07 -0400)
"data" is currently leaked when the prepare_layoutcommit operation
returns an error. Put the cred before taking the spinlock in that
case, take the lock and then goto out_unlock which will drop the
lock and then free "data".

Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/pnfs.c

index 18aa3b7962eb97253232fc34377141bbeaf89b1b..70bf706b10904e156affe9dd4bea2ec9a17776c5 100644 (file)
@@ -2221,13 +2221,12 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
        if (ld->prepare_layoutcommit) {
                status = ld->prepare_layoutcommit(&data->args);
                if (status) {
+                       put_rpccred(data->cred);
                        spin_lock(&inode->i_lock);
                        set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags);
                        if (end_pos > nfsi->layout->plh_lwb)
                                nfsi->layout->plh_lwb = end_pos;
-                       spin_unlock(&inode->i_lock);
-                       put_rpccred(data->cred);
-                       goto clear_layoutcommitting;
+                       goto out_unlock;
                }
        }