[Devel] [PATCH 2/2] Add a cleanup routine for objhash socket objects

Dan Smith danms at us.ibm.com
Tue Sep 15 09:52:11 PDT 2009


This cleanup routine checks for unattached sockets that we instantiated
and calls sock_release() on them to avoid leaking the struct socket when
their buffers are consumed and the struct sock is free'd.

Signed-off-by: Dan Smith <danms at us.ibm.com>
---
 checkpoint/objhash.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/checkpoint/objhash.c b/checkpoint/objhash.c
index 9750483..5626707 100644
--- a/checkpoint/objhash.c
+++ b/checkpoint/objhash.c
@@ -247,6 +247,18 @@ static void obj_sock_drop(void *ptr)
 	sock_put((struct sock *) ptr);
 }
 
+static void cleanup_sock(void *ptr)
+{
+	struct sock *sk = (struct sock *) ptr;
+
+	if (sk->sk_socket && !sk->sk_socket->file) {
+		struct socket *sock = sk->sk_socket;
+		sock_orphan(sk);
+		sock->sk = NULL;
+		sock_release(sock);
+	}
+}
+
 static struct ckpt_obj_ops ckpt_obj_ops[] = {
 	/* ignored object */
 	{
@@ -384,6 +396,7 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = {
 		.ref_grab = obj_sock_grab,
 		.checkpoint = checkpoint_sock,
 		.restore = restore_sock,
+		.cleanup = cleanup_sock,
 	},
 };
 
-- 
1.6.2.5

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list