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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add mechanism in xs_setup_local() to safely tear xprt down and
solve the socket leak problem.

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

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;
 }
 
-- 
2.17.1




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux