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 <avagin@virtuozzo.com>
Message-Id: <1460050184-6293-2-git-send-email-avagin@openvz.org>
  • Loading branch information
avagin committed Apr 8, 2016
1 parent 658ccd4 commit f9c7d7f
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 f9c7d7f

Please sign in to comment.