From patchwork Mon Jan 28 21:14:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 216374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 08E292C009B for ; Tue, 29 Jan 2013 08:22:59 +1100 (EST) Received: from localhost ([::1]:47231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzwAL-0001Vl-42 for incoming@patchwork.ozlabs.org; Mon, 28 Jan 2013 16:22:57 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzwAD-0001V0-Qo for qemu-devel@nongnu.org; Mon, 28 Jan 2013 16:22:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzwAC-0005Fm-JY for qemu-devel@nongnu.org; Mon, 28 Jan 2013 16:22:49 -0500 Received: from mail-ia0-x22c.google.com ([2607:f8b0:4001:c02::22c]:35423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzwAC-0005Ff-DJ for qemu-devel@nongnu.org; Mon, 28 Jan 2013 16:22:48 -0500 Received: by mail-ia0-f172.google.com with SMTP id u8so4990746iag.31 for ; Mon, 28 Jan 2013 13:22:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=AnDrtx2dZ7KWLkSrZCUYZlK4rhIRHeG6va5XIofnq34=; b=NL42X/VPJjV2PRvwPwgAoDO6WMsV13AT/ghgreK/Y8Xz1JERNyHPvz8Q3s9d9xUPgn QNsFXgMtywqnvi9GAZKQyy5zqQYjml7tIUNLUYylY4tW3oscBKb1o2cQMLdEB/OMOUka q5TZrLokI083IHlkFdwHi/cAc8+tpH9dexgurGg4ZNPtv8t9ZmtSLP34zjlIeJ3zhwjb ZZhnJ5fus7Ec9XNg8yjGBHfFcLcA+YJ+MmFyooaiPj9p4M09V6YewJDb/1buMf4Lwjea c2EUAV+4Ok8cCUwSw3WGeoOL8L7Yx4g3aH1Iu4Ticlnl/vyIOJk3iZdbCx64BZR3k908 smGg== X-Received: by 10.50.12.133 with SMTP id y5mr6094912igb.108.1359407743026; Mon, 28 Jan 2013 13:15:43 -0800 (PST) Received: from localhost ([32.97.110.59]) by mx.google.com with ESMTPS id fv6sm6955288igc.17.2013.01.28.13.15.41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 28 Jan 2013 13:15:42 -0800 (PST) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2013 15:14:55 -0600 Message-Id: <1359407695-17792-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359407695-17792-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1359407695-17792-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c02::22c Cc: aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster Spotted by Coverity. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Luiz Capitulino Signed-off-by: Michael Roth --- 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 498f5ca..7a0202e 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;