Skip to content

Commit de98dc9

Browse files
colo-ftmdroth
authored andcommitted
libcacard: fix resource leak
In function connect_to_qemu(), getaddrinfo() will allocate memory that is stored into server, it should be freed by using freeaddrinfo() before connect_to_qemu() return. Cc: [email protected] Reviewed-by: Markus Armbruster <[email protected]> Signed-off-by: zhanghailiang <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 5bbebf6) Signed-off-by: Michael Roth <[email protected]>
1 parent 0c80570 commit de98dc9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libcacard/vscclient.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ connect_to_qemu(
597597
const char *port
598598
) {
599599
struct addrinfo hints;
600-
struct addrinfo *server;
600+
struct addrinfo *server = NULL;
601601
int ret, sock;
602602

603603
sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -629,9 +629,14 @@ connect_to_qemu(
629629
if (verbose) {
630630
printf("Connected (sizeof Header=%zd)!\n", sizeof(VSCMsgHeader));
631631
}
632+
633+
freeaddrinfo(server);
632634
return sock;
633635

634636
cleanup_socket:
637+
if (server) {
638+
freeaddrinfo(server);
639+
}
635640
closesocket(sock);
636641
return -1;
637642
}

0 commit comments

Comments
 (0)