[CRIU] [PATCH 1/2] sk-tcp: fix memory leak

Andrey Vagin avagin at openvz.org
Sat Apr 6 17:20:29 EDT 2013


CID 996187 (#1 of 1): Resource leak (RESOURCE_LEAK)
10. leaked_storage: Variable "buf" going out of scope leaks the storage it points to.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 sk-tcp.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/sk-tcp.c b/sk-tcp.c
index 7c762d5..4178ae6 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -409,7 +409,7 @@ static int restore_tcp_seqs(int sk, TcpStreamEntry *tse)
 
 static int send_tcp_queue(int sk, int queue, u32 len, int imgfd)
 {
-	int ret;
+	int ret, err = -1;
 	char *buf;
 
 	pr_debug("\tRestoring TCP %d queue data %u bytes\n", queue, len);
@@ -424,19 +424,20 @@ static int send_tcp_queue(int sk, int queue, u32 len, int imgfd)
 		return -1;
 
 	if (read_img_buf(imgfd, buf, len) < 0)
-		return -1;
+		goto err;
 
 	ret = send(sk, buf, len, 0);
-
-	xfree(buf);
-
 	if (ret != len) {
 		pr_perror("Can't restore %d queue data (%d), want %d",
 				queue, ret, len);
-		return -1;
+		goto err;
 	}
 
-	return 0;
+	err = 0;
+err:
+	xfree(buf);
+
+	return err;
 }
 
 static int restore_tcp_queues(int sk, TcpStreamEntry *tse, int fd)
-- 
1.7.11.7



More information about the CRIU mailing list