NFS: direct.c: Fix memory leak of dreq when nfs_get_lock_context fails
authorMisono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Wed, 28 Aug 2019 08:01:22 +0000 (17:01 +0900)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Sun, 22 Mar 2020 20:47:58 +0000 (16:47 -0400)
When dreq is allocated by nfs_direct_req_alloc(), dreq->kref is
initialized to 2. Therefore we need to call nfs_direct_req_release()
twice to release the allocated dreq. Usually it is called in
nfs_file_direct_{read, write}() and nfs_direct_complete().

However, current code only calls nfs_direct_req_relese() once if
nfs_get_lock_context() fails in nfs_file_direct_{read, write}().
So, that case would result in memory leak.

Fix this by adding the missing call.

Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/direct.c

index b768a0b42e82e857d251dadca061e25811c38c84..ade2435551c89a307b2ce4e51ef603591bee0924 100644 (file)
@@ -571,6 +571,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter)
        l_ctx = nfs_get_lock_context(dreq->ctx);
        if (IS_ERR(l_ctx)) {
                result = PTR_ERR(l_ctx);
+               nfs_direct_req_release(dreq);
                goto out_release;
        }
        dreq->l_ctx = l_ctx;
@@ -990,6 +991,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
        l_ctx = nfs_get_lock_context(dreq->ctx);
        if (IS_ERR(l_ctx)) {
                result = PTR_ERR(l_ctx);
+               nfs_direct_req_release(dreq);
                goto out_release;
        }
        dreq->l_ctx = l_ctx;