Skip to content

Commit

Permalink
Merge pull request #147 from trilogy-libraries/plug-ai_addr-leak
Browse files Browse the repository at this point in the history
Plug small memory leak in socket resolution
  • Loading branch information
jhawthorn authored Jan 4, 2024
2 parents 46af52f + 68f03d5 commit 15ec0c1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ static int _cb_raw_close(trilogy_sock_t *_sock)
if (sock->fd != -1) {
rc = close(sock->fd);
}

if (sock->addr) {
freeaddrinfo(sock->addr);
if (sock->base.opts.hostname == NULL && sock->base.opts.path != NULL) {
/* We created these with calloc so must free them instead of calling freeaddrinfo */
free(sock->addr->ai_addr);
free(sock->addr);
} else {
freeaddrinfo(sock->addr);
}
}

free(sock->base.opts.hostname);
Expand Down

0 comments on commit 15ec0c1

Please sign in to comment.