diff options
author | Markus Armbruster <armbru@redhat.com> | 2013-01-16 18:15:09 +0100 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2013-01-28 13:46:54 -0600 |
commit | 10a2158f52796e5b2b7ce7991bde09a3c985a37b (patch) | |
tree | 1231e40491b77a7c31bbac9756eb9b55f2233085 /qga | |
parent | 6f6867493cc00974de594a509cee5a3be61c64aa (diff) | |
download | qemu-10a2158f52796e5b2b7ce7991bde09a3c985a37b.tar.gz qemu-10a2158f52796e5b2b7ce7991bde09a3c985a37b.tar.bz2 qemu-10a2158f52796e5b2b7ce7991bde09a3c985a37b.zip |
qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths
Spotted by Coverity.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga')
-rw-r--r-- | qga/commands-posix.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 498f5ca46a..7a0202eb2a 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -935,9 +935,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) error_setg_errno(errp, errno, "failed to get MAC address of %s", ifa->ifa_name); + close(sock); goto error; } + close(sock); mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; info->value->hardware_address = @@ -947,20 +949,19 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) (int) mac_addr[4], (int) mac_addr[5]); info->value->has_hardware_address = true; - close(sock); } if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { /* interface with IPv4 address */ - address_item = g_malloc0(sizeof(*address_item)); - address_item->value = g_malloc0(sizeof(*address_item->value)); p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) { error_setg_errno(errp, errno, "inet_ntop failed"); goto error; } + address_item = g_malloc0(sizeof(*address_item)); + address_item->value = g_malloc0(sizeof(*address_item->value)); address_item->value->ip_address = g_strdup(addr4); address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4; @@ -973,14 +974,14 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) } else if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6) { /* interface with IPv6 address */ - address_item = g_malloc0(sizeof(*address_item)); - address_item->value = g_malloc0(sizeof(*address_item->value)); p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) { error_setg_errno(errp, errno, "inet_ntop failed"); goto error; } + address_item = g_malloc0(sizeof(*address_item)); + address_item->value = g_malloc0(sizeof(*address_item->value)); address_item->value->ip_address = g_strdup(addr6); address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6; |