aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>2017-07-26 23:42:11 -0300
committerMichael Tokarev <mjt@tls.msk.ru>2017-07-31 13:06:38 +0300
commit9f26f3252534e7680cfc7c0dbd1d79fdb56519ad (patch)
treeca62c732b407a9385f52ba8ca046dd5a13439194 /ui
parentf80ac75d0e6e6e7481d61cdb86e5a741a442f100 (diff)
downloadqemu-9f26f3252534e7680cfc7c0dbd1d79fdb56519ad.zip
qemu-9f26f3252534e7680cfc7c0dbd1d79fdb56519ad.tar.gz
qemu-9f26f3252534e7680cfc7c0dbd1d79fdb56519ad.tar.bz2
ui/vnc: fix leak of SocketAddress **
Extract the (correct) cleaning code as a new function vnc_free_addresses() then use it to remove the memory leaks. Reported-by: Clang Static Analyzer Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'ui')
-rw-r--r--ui/vnc.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/ui/vnc.c b/ui/vnc.c
index eb91559..651cbb8 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3521,6 +3521,20 @@ static int vnc_display_get_address(const char *addrstr,
return ret;
}
+static void vnc_free_addresses(SocketAddress ***retsaddr,
+ size_t *retnsaddr)
+{
+ size_t i;
+
+ for (i = 0; i < *retnsaddr; i++) {
+ qapi_free_SocketAddress((*retsaddr)[i]);
+ }
+ g_free(*retsaddr);
+
+ *retsaddr = NULL;
+ *retnsaddr = 0;
+}
+
static int vnc_display_get_addresses(QemuOpts *opts,
bool reverse,
SocketAddress ***retsaddr,
@@ -3538,7 +3552,6 @@ static int vnc_display_get_addresses(QemuOpts *opts,
bool has_ipv6 = qemu_opt_get(opts, "ipv6");
bool ipv4 = qemu_opt_get_bool(opts, "ipv4", false);
bool ipv6 = qemu_opt_get_bool(opts, "ipv6", false);
- size_t i;
int displaynum = -1;
int ret = -1;
@@ -3614,16 +3627,8 @@ static int vnc_display_get_addresses(QemuOpts *opts,
ret = 0;
cleanup:
if (ret < 0) {
- for (i = 0; i < *retnsaddr; i++) {
- qapi_free_SocketAddress((*retsaddr)[i]);
- }
- g_free(*retsaddr);
- for (i = 0; i < *retnwsaddr; i++) {
- qapi_free_SocketAddress((*retwsaddr)[i]);
- }
- g_free(*retwsaddr);
- *retsaddr = *retwsaddr = NULL;
- *retnsaddr = *retnwsaddr = 0;
+ vnc_free_addresses(retsaddr, retnsaddr);
+ vnc_free_addresses(retwsaddr, retnwsaddr);
}
return ret;
}
@@ -3772,7 +3777,6 @@ void vnc_display_open(const char *id, Error **errp)
int acl = 0;
int lock_key_sync = 1;
int key_delay_ms;
- size_t i;
if (!vd) {
error_setg(errp, "VNC display not active");
@@ -3993,12 +3997,8 @@ void vnc_display_open(const char *id, Error **errp)
}
cleanup:
- for (i = 0; i < nsaddr; i++) {
- qapi_free_SocketAddress(saddr[i]);
- }
- for (i = 0; i < nwsaddr; i++) {
- qapi_free_SocketAddress(wsaddr[i]);
- }
+ vnc_free_addresses(&saddr, &nsaddr);
+ vnc_free_addresses(&wsaddr, &nwsaddr);
return;
fail: