diff mbox series

[3/3] SUNRPC: Fix local socket leak in xs_setup_local()

Message ID 20220511132232.4030-4-wanghai38@huawei.com (mailing list archive)
State New
Headers show
Series Refix the socket leak in xs_setup_local() | expand

Commit Message

wanghai (M) May 11, 2022, 1:22 p.m. UTC
Add mechanism in xs_setup_local() to safely tear xprt down and
solve the socket leak problem.

Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 net/sunrpc/xprtsock.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 25b8a8ead56b..7b9a62750571 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -1264,6 +1264,18 @@  static void xs_xprt_free(struct rpc_xprt *xprt)
 	xprt_free(xprt);
 }
 
+/**
+ * xs_destroy_xprt - close xprt socket and destroy it.
+ */
+static void xs_destroy_xprt(struct work_struct *work)
+{
+	struct rpc_xprt *xprt =
+		container_of(work, struct rpc_xprt, task_cleanup);
+
+	xs_close(xprt);
+	xs_xprt_free(xprt);
+}
+
 /**
  * xs_destroy - prepare to shutdown a transport
  * @xprt: doomed transport
@@ -2891,7 +2903,9 @@  static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
 		return xprt;
 	ret = ERR_PTR(-EINVAL);
 out_err:
-	xs_xprt_free(xprt);
+
+	INIT_WORK(&xprt->task_cleanup, xs_destroy_xprt);
+	schedule_work(&xprt->task_cleanup);
 	return ret;
 }