Skip to content

Commit 0be8569

Browse files
committed
client session BUGFIX memory leak
Fixes #292
1 parent bd33aec commit 0be8569

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/session_client.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ nc_sock_connect(const char *host, uint16_t port, int timeout, struct nc_keepaliv
13601360
{
13611361
int i, opt;
13621362
int sock = sock_pending ? *sock_pending : -1;
1363-
struct addrinfo hints, *res_list, *res;
1363+
struct addrinfo hints, *res_list = NULL, *res;
13641364
char *buf, port_s[6]; /* length of string representation of short int */
13651365
void *addr;
13661366

@@ -1388,7 +1388,7 @@ nc_sock_connect(const char *host, uint16_t port, int timeout, struct nc_keepaliv
13881388
continue;
13891389
} else {
13901390
/* timeout, keep pending socket */
1391-
return -1;
1391+
break;
13921392
}
13931393
}
13941394
VRB("Successfully connected to %s:%s over %s.", host, port_s, (res->ai_family == AF_INET6) ? "IPv6" : "IPv4");
@@ -1431,6 +1431,9 @@ nc_sock_connect(const char *host, uint16_t port, int timeout, struct nc_keepaliv
14311431
return sock;
14321432

14331433
error:
1434+
if (res_list) {
1435+
freeaddrinfo(res_list);
1436+
}
14341437
if (sock != -1) {
14351438
close(sock);
14361439
}

0 commit comments

Comments
 (0)