aboutsummaryrefslogtreecommitdiff
path: root/libcacard
diff options
context:
space:
mode:
authorzhanghailiang <zhang.zhanghailiang@huawei.com>2014-11-14 10:18:08 +0800
committerMichael Roth <mdroth@linux.vnet.ibm.com>2015-01-07 14:45:17 -0600
commitde98dc9539e31b8f986e5d7aad22988beecc2028 (patch)
tree2d2d90b1b7b14caedec4936859cebf922fe71b3a /libcacard
parent0c80570170eb9c489657df5b85e3d3104952ce0e (diff)
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: qemu-stable@nongnu.org Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit 5bbebf622897a59db5da4c468e737bfec4d71280) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'libcacard')
-rw-r--r--libcacard/vscclient.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index 80111df00c..fa6041de99 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -597,7 +597,7 @@ connect_to_qemu(
const char *port
) {
struct addrinfo hints;
- struct addrinfo *server;
+ struct addrinfo *server = NULL;
int ret, sock;
sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -629,9 +629,14 @@ connect_to_qemu(
if (verbose) {
printf("Connected (sizeof Header=%zd)!\n", sizeof(VSCMsgHeader));
}
+
+ freeaddrinfo(server);
return sock;
cleanup_socket:
+ if (server) {
+ freeaddrinfo(server);
+ }
closesocket(sock);
return -1;
}