From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvY1m-00085p-Je for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:47:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvY1k-0005lT-7v for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:47:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18205) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvY1k-0005lF-0y for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:47:56 -0500 Date: Wed, 16 Jan 2013 16:46:21 -0200 From: Luiz Capitulino Message-ID: <20130116164621.79cd0127@doriath.home> In-Reply-To: <1358356509-28742-3-git-send-email-armbru@redhat.com> References: <1358356509-28742-1-git-send-email-armbru@redhat.com> <1358356509-28742-3-git-send-email-armbru@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com On Wed, 16 Jan 2013 18:15:09 +0100 Markus Armbruster wrote: > Spotted by Coverity. I'd split that patch, but you don't have to respin just because of that. > > Signed-off-by: Markus Armbruster > --- > qga/commands-posix.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index f95ebc8..d6902a9 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; > > if (asprintf(&info->value->hardware_address, > @@ -950,20 +952,19 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) > } > > 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; > > @@ -976,14 +977,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; >