Skip to content

Commit

Permalink
sk-tcp: fix memory leak
Browse files Browse the repository at this point in the history
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@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
avagin authored and xemul committed Apr 9, 2013
1 parent 7c02f65 commit 17e2dad
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sk-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit 17e2dad

Please sign in to comment.