Skip to content

Commit

Permalink
util: don't leak a socket
Browse files Browse the repository at this point in the history
CID 159478 (#2 of 2): Resource leak (RESOURCE_LEAK)
8. leaked_handle: Handle variable sk going out of scope leaks the handle.

Signed-off-by: Andrew Vagin <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
avagin committed Apr 8, 2016
1 parent 06f48c9 commit 575542d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions criu/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,17 +1189,18 @@ int setup_tcp_client(char *addr)

pr_info("Connecting to server %s:%u\n", addr, (int)ntohs(opts.port));

if (get_sockaddr_in(&saddr, addr))
return -1;

sk = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sk < 0) {
pr_perror("Can't create socket");
return -1;
}

if (get_sockaddr_in(&saddr, addr))
return -1;

if (connect(sk, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
pr_perror("Can't connect to server");
close(sk);
return -1;
}

Expand Down

0 comments on commit 575542d

Please sign in to comment.