From 17e2daddf2a8fe1bc45c49e95329cad226eec69d Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Wed, 10 Apr 2013 00:56:20 +0400 Subject: [PATCH] sk-tcp: fix memory leak 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 Signed-off-by: Pavel Emelyanov --- sk-tcp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sk-tcp.c b/sk-tcp.c index e23d6b0b9..358951617 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)