From patchwork Mon Dec 13 11:15:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 12673727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36A68C433FE for ; Mon, 13 Dec 2021 11:18:06 +0000 (UTC) Received: from localhost ([::1]:33934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwjLJ-0002ZX-AX for qemu-devel@archiver.kernel.org; Mon, 13 Dec 2021 06:18:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwjJU-0008Vz-CP for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:12 -0500 Received: from [2a00:1450:4864:20::52a] (port=42715 helo=mail-ed1-x52a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwjJS-0007FV-Ea for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:12 -0500 Received: by mail-ed1-x52a.google.com with SMTP id r11so50238159edd.9 for ; Mon, 13 Dec 2021 03:16:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=UOq7HXf+K8oMudzzz7NHQ+jQVflm2qA+bj7AzU+PASI=; b=sFtXHZJzIKgcGpBwUs+JNSib1s5iRrXfkAAAcRX+NSJx1hC4sjDYBaL2J92hoqkFAa xXke3SZH4C5ZvTyJF6OnLIctlTgo3IK/OGyVMLIX+/MA2Kb4nDSJKUVb5gmY4STRG4zY HbOBNzz25cETmGAaEgJFhr/hyXLfEp1y3hnKoGe3bBdDX4bnPWqYir0Pdh6iyzjWGsDs QVpJNm2vniDOktf62G5lr2xq85iYLnTi3TYWLNwomimi65M0PIdfYsRwxkEI+4g8XKUH wL+WzLCPIaviMxgn2FVD12RiyX3BVtqxeHgdbKSoWUxj2In++uIEA+KsrmSdaVURNlda 4PLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UOq7HXf+K8oMudzzz7NHQ+jQVflm2qA+bj7AzU+PASI=; b=HGzYVdz467bpAsWo92EOtbpXq5MQQl+6JzN4i8CXfv8JIqKs8cpH+6NEMr7/c1wsQ7 k3hVeK1i7SjHuelocZe8jyMja/9/cC0DJqOneS2gp1Er2AlQ/kySHdxb2prPfqoaspTj KVjBDqL3xJQwqVcQVquzN5OilDz3N2Dh2L8hRxF+Q8rPxTRf5sMJcaILhRk2P6nykk/S 83WtLHPFGKnN0fGGjCUb/s36wHurhYUKhP2LVU83qiUJS1LSAjKUGgS5ZmVog1LAfgbh I5c8hZwuNK9tYiY+7m1avDYDFu5iGy0rk/jGAjJTBp/faBZB/HfZEqv5GfTOg18DkYc9 VuuA== X-Gm-Message-State: AOAM531DwZx5uOU5PGhQei3IAiOinvryLHnpHPrmfP3+CvPhHU9Xwbri /CJEQOMag7hf0oi7aXpLfr+hP6mgxZ734g== X-Google-Smtp-Source: ABdhPJxPWDn1mFyH8gk3X7PBRa9eGUFEI04KngwIWTauWTcOlrA0foHSD+6GS+9ziK5jYsbnzB3dzw== X-Received: by 2002:a50:c35b:: with SMTP id q27mr63056301edb.154.1639394166451; Mon, 13 Dec 2021 03:16:06 -0800 (PST) Received: from kostyanf14nb.Dlink ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id a13sm6139384edk.29.2021.12.13.03.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 03:16:05 -0800 (PST) From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Michael Roth , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/5] gqa-win: get_pci_info: Clean dev_info if handle is valid Date: Mon, 13 Dec 2021 13:15:50 +0200 Message-Id: <20211213111554.62394-2-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213111554.62394-1-konstantin@daynix.com> References: <20211213111554.62394-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52a (failed) Received-SPF: none client-ip=2a00:1450:4864:20::52a; envelope-from=konstantin@daynix.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4e84afd83b..3dd74fe225 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -514,7 +514,7 @@ DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT, static GuestPCIAddress *get_pci_info(int number, Error **errp) { - HDEVINFO dev_info; + HDEVINFO dev_info = INVALID_HANDLE_VALUE; SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DATA dev_iface_data; HANDLE dev_file; @@ -749,7 +749,9 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } free_dev_info: - SetupDiDestroyDeviceInfoList(dev_info); + if (dev_info != INVALID_HANDLE_VALUE) { + SetupDiDestroyDeviceInfoList(dev_info); + } out: return pci; } From patchwork Mon Dec 13 11:15:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 12673731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2525C4332F for ; Mon, 13 Dec 2021 11:18:06 +0000 (UTC) Received: from localhost ([::1]:34088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwjLJ-0002fq-NH for qemu-devel@archiver.kernel.org; Mon, 13 Dec 2021 06:18:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwjJW-0008WH-3R for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:15 -0500 Received: from [2a00:1450:4864:20::52f] (port=42720 helo=mail-ed1-x52f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwjJS-0007Ff-GX for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:13 -0500 Received: by mail-ed1-x52f.google.com with SMTP id r11so50238316edd.9 for ; Mon, 13 Dec 2021 03:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=mMxX3If9fTUUjGK3dbCE2gziT93rl8rcCI1gT1hsj0o=; b=YQWbPTzWjE/zhrhyUcnkrVQdmcrZ0XeL29Q5wJ/szVWPVWhccKtUzbhXCKA5fmu5Q1 bShuIH5YHZUGp4ORLntd9kA++NDiuw1hlC9GEwXA+o+IjCyN2BazeodWeQPPFzZMqd2R cd2kuM4eQMYna3hPAxCD+M5uJa0QEaLic++65hUreuV0gahubY0cbRqODVfz5NsJ8sYG grTetEXkQK2frk07iplg2Pkn5OFejb/NUuOgABntT6YIHTPF9btHJr5WQleJL2dMGUA/ HuSzKdlu4ucISTCJ7VvJPbSbi75MrZLq2H8eYpTCw1kgNzVdh7y7Ij0PcCU+0tNiswZh deaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mMxX3If9fTUUjGK3dbCE2gziT93rl8rcCI1gT1hsj0o=; b=o+P0w99D3EDDuNTQU2RXHfg+Kk8/81VxlF9G5btW1TIhpy8NAyhbnOpjElOMx4PIrX gEtD1VprBgEIgvJb+PBdVGaI7IA+94SF7aMD4B55T4np1AeEmuBFFLnjkPNSrQc5zDnI kQ9lTfcRQlAg4jPPbFuXwhZGTOzscvR61B58WDBIC1AAruM6qzElLFl1FZXW8hwJK9Mo Mwm2d+JYSUDf+tau8ZljkmeT1Ghi5BCwESfBtj2OSDrkACb8Yi5p1e036QuYHOtsU2NF bWeF4d4z2FpdZhTZwFs3KTFcaSAdk6rkvCPCW/q6K15gvqTA1Du36Zhs4nMHVsnRiso6 aUng== X-Gm-Message-State: AOAM530rL0C0QGEeccFOrFA8j1g0Exw7/0ogW9SHU2Xy9VeiKD++3WaW s+bTBCNkvTXdEIw5h+6m1HHQ5nbAb9bblw== X-Google-Smtp-Source: ABdhPJzkiw/Kj1mO0Ffiu8824fNwt0vSYsmnoZCdrsVW5JU+7WHPKrctN0886VdcwYVrNApw9OUgZQ== X-Received: by 2002:a05:6402:5206:: with SMTP id s6mr64355859edd.286.1639394167356; Mon, 13 Dec 2021 03:16:07 -0800 (PST) Received: from kostyanf14nb.Dlink ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id a13sm6139384edk.29.2021.12.13.03.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 03:16:07 -0800 (PST) From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Michael Roth , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 2/5] gqa-win: get_pci_info: Use common 'cleanup' label Date: Mon, 13 Dec 2021 13:15:51 +0200 Message-Id: <20211213111554.62394-3-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213111554.62394-1-konstantin@daynix.com> References: <20211213111554.62394-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52f (failed) Received-SPF: none client-ip=2a00:1450:4864:20::52f; envelope-from=konstantin@daynix.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To prevent memory leaks, always try to free initialized variables. Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 3dd74fe225..12f7a88078 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -532,7 +532,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to get devices tree"); - goto out; + goto cleanup; } g_debug("enumerating devices"); @@ -562,7 +562,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } else { error_setg_win32(errp, GetLastError(), "failed to get device interfaces"); - goto free_dev_info; + goto cleanup; } } @@ -576,7 +576,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) CloseHandle(dev_file); error_setg_win32(errp, GetLastError(), "failed to get device slot number"); - goto free_dev_info; + goto cleanup; } CloseHandle(dev_file); @@ -586,7 +586,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } else { error_setg_win32(errp, GetLastError(), "failed to get device interfaces"); - goto free_dev_info; + goto cleanup; } g_debug("found device slot %d. Getting storage controller", number); @@ -603,7 +603,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } else { error_setg_win32(errp, GetLastError(), "failed to get device instance ID"); - goto out; + goto cleanup; } } @@ -617,14 +617,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) g_error("CM_Locate_DevInst failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get device instance"); - goto out; + goto cleanup; } cr = CM_Get_Parent(&parent_dev_inst, dev_inst, 0); if (cr != CR_SUCCESS) { g_error("CM_Get_Parent failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get parent device instance"); - goto out; + goto cleanup; } cr = CM_Get_Device_ID_Size(&dev_id_size, parent_dev_inst, 0); @@ -632,7 +632,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) g_error("CM_Get_Device_ID_Size failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get parent device ID length"); - goto out; + goto cleanup; } ++dev_id_size; @@ -647,7 +647,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) g_error("CM_Get_Device_ID failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get parent device ID"); - goto out; + goto cleanup; } } @@ -661,14 +661,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) if (parent_dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to get parent device"); - goto out; + goto cleanup; } parent_dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); if (!SetupDiEnumDeviceInfo(parent_dev_info, 0, &parent_dev_info_data)) { error_setg_win32(errp, GetLastError(), "failed to get parent device data"); - goto out; + goto cleanup; } for (j = 0; @@ -748,11 +748,10 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) break; } -free_dev_info: +cleanup: if (dev_info != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(dev_info); } -out: return pci; } From patchwork Mon Dec 13 11:15:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 12673729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36A3BC433EF for ; Mon, 13 Dec 2021 11:18:06 +0000 (UTC) Received: from localhost ([::1]:33924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwjLI-0002ZG-Ty for qemu-devel@archiver.kernel.org; Mon, 13 Dec 2021 06:18:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwjJU-0008W0-HN for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:12 -0500 Received: from [2a00:1450:4864:20::52a] (port=35574 helo=mail-ed1-x52a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwjJS-0007Fl-GY for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:12 -0500 Received: by mail-ed1-x52a.google.com with SMTP id v1so51262934edx.2 for ; Mon, 13 Dec 2021 03:16:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZyjWKDKqH2alTErU781Viw3hW4bS53yAycPis4lhQRk=; b=wyu3kJG6fWDQX1PeUxnjK2xOP5Cttq05VZCASbif9/HeTqb8imyw9LueiingxDy+vX hsA2PtnKKFBKHG7TFOA436UqLRi3UIp/CcIhceZRa1Q+oli1S7wrhxLcavUt8/xEpwIN 3FlgEEKVjLxElcDYPs0OJ0FsWVy0x/jHW16bSWKUXKhrV2QW/OQ0iWJY2eWpPlYECWmx gpoZVEYaRKxl420NI9YHxfnYa47EqivMipZNPN6zHBnJAwmLenM7neBkT6tfFIZ0koG6 AW2pQSuFnvZ46XZGUSaxSAjqfyQoWlYmw+BBXZsHje+rATOvsbR9EfwQMDiQN8lAj3lu X1WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZyjWKDKqH2alTErU781Viw3hW4bS53yAycPis4lhQRk=; b=7dWbgSEkvSq722H2DzNsn07Kb1lfTa3rTkmrX0Mdy6FpaSmUzulziylX+coGJHi2de tSFLLRX2DAFNWLwxreC+NZEWsDWPBy0QZy7Rhzm56HRmQ57t3srzT1hngjwt+zUP+z68 zKaCHtB8quTcjcymCrD+rowG+zocpxUjeGT2pLsG1kLEWTJkQYPkJn4F8X7T+Z2SC1uz 6Er9sXnEw4lPOeHxZOjaK+NFdI0zECgtoohTQqtS/Zx4sBR6ybKx4vtV1QNhbnWWIx9+ j/Ikd6tfoFom+bdHKAODQ1CPU1DqryV+5/P2026FGwwbjATp7nt9luIztOQLrtjyn37p aOYw== X-Gm-Message-State: AOAM531cWg4tE6a6bfqnKfC5JicGxoxmzVjvMCUNCVRzWvEwcCZgrxsV MjPgtqiS/80F8pgZtJH1rWbeFJdqAkXWTw== X-Google-Smtp-Source: ABdhPJzoft/rmap85EooIh5zWWrRDafibkeMhEYz/XPWAydZ7+PoY4niLLim2T+StAV/GUyKdlcycw== X-Received: by 2002:aa7:db47:: with SMTP id n7mr63959186edt.303.1639394168294; Mon, 13 Dec 2021 03:16:08 -0800 (PST) Received: from kostyanf14nb.Dlink ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id a13sm6139384edk.29.2021.12.13.03.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 03:16:07 -0800 (PST) From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Michael Roth , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 3/5] gqa-win: get_pci_info: Free parent_dev_info properly Date: Mon, 13 Dec 2021 13:15:52 +0200 Message-Id: <20211213111554.62394-4-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213111554.62394-1-konstantin@daynix.com> References: <20211213111554.62394-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52a (failed) Received-SPF: none client-ip=2a00:1450:4864:20::52a; envelope-from=konstantin@daynix.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In case when the function fails to get parent device data, the parent_dev_info variable will be initialized, but not freed. Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 12f7a88078..cef14a8762 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -515,6 +515,8 @@ DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT, static GuestPCIAddress *get_pci_info(int number, Error **errp) { HDEVINFO dev_info = INVALID_HANDLE_VALUE; + HDEVINFO parent_dev_info = INVALID_HANDLE_VALUE; + SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DATA dev_iface_data; HANDLE dev_file; @@ -542,7 +544,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL; STORAGE_DEVICE_NUMBER sdn; char *parent_dev_id = NULL; - HDEVINFO parent_dev_info; SP_DEVINFO_DATA parent_dev_info_data; DWORD j; DWORD size = 0; @@ -744,11 +745,13 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) break; } } - SetupDiDestroyDeviceInfoList(parent_dev_info); break; } cleanup: + if (parent_dev_info != INVALID_HANDLE_VALUE) { + SetupDiDestroyDeviceInfoList(parent_dev_info); + } if (dev_info != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(dev_info); } From patchwork Mon Dec 13 11:15:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 12673767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 713DEC433F5 for ; Mon, 13 Dec 2021 11:24:55 +0000 (UTC) Received: from localhost ([::1]:44260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwjRu-0001Bk-Dj for qemu-devel@archiver.kernel.org; Mon, 13 Dec 2021 06:24:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwjJW-0008WI-Fs for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:15 -0500 Received: from [2a00:1450:4864:20::52f] (port=37457 helo=mail-ed1-x52f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwjJT-0007Fp-9j for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:13 -0500 Received: by mail-ed1-x52f.google.com with SMTP id e3so51520323edu.4 for ; Mon, 13 Dec 2021 03:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7sBF+Qy7/vzAjQ+8VJmnouHX5HxqVw+CgpLyJxT4k1k=; b=NRqDmXorx8tsujvCUJOAt/z7zgkL29eL4O4bpgM4Jotg4Odx33X2p3ICUmSNY25cv2 7QiMBSXHb8+9mxMzhGEWp1CBfZyLYA+H0PQhWTyZM5rWU+BxB2v96CdHZlBT5V8IHhge qhDFaBb6UajJ+aVArA4oMW6+cwqMU8CcxErYZ67uyd0pcPZRQ8Q0Y9yfXfWXre//FeC3 pZhUaxXf/6P7/flMfdladYBnrcN83yydG0Z7nKqsQCaPHC3ogViFcFy97t+i8bD2PRyl gAKrynHNg18+VZiqKmh0rJ+1qteb8ZCCFuYKswbNPK7m6GaOGtbunRzDMh/0Gl4h1Lxv PF1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7sBF+Qy7/vzAjQ+8VJmnouHX5HxqVw+CgpLyJxT4k1k=; b=d2jCkqup0l0JLy8+bC7xyblnMqLOvrssxpX4ZwnWWkx0zMsYrT0f5BrHOaMzvqR4vM b4z8CoBBdI4ZfKZHxmgEcHDEinP8UnQAdxsHgPf/tyoL70Jk/BQMUfzEhX0Qx8AyEuP+ 6DjOEFvMepxjgKdA2nz6+MqZsyGN3PVpEWbGauEXNg+cVTaadJ4uW2sIyy3TQEACa1Z/ aKliwry1SWxg+W3cZjQpCASIPYDz7Q439TWOYCgKpnSBBlt3UO9QnpJisjWBmnl9Le5p jSzxw61LJsOounnGY8LlhBn78IsDJbmLHm7v0N9butENCse6+wO1Mm7m4Lm5UGIE2bPW gz4g== X-Gm-Message-State: AOAM5304vP+LY8Wc+kqYpb3WE+DY4Mvei4ubxoEsZU6exsBRApFvIVhj tA9MR9a2v36Tcf43ETihPbReaKKfS90unw== X-Google-Smtp-Source: ABdhPJyxaZbWeHq0nWOg9jKWpG8hywPhAzhu9QiMaeVHylK8lEQW3sxZtullFO5O//WCL5dFYhh54A== X-Received: by 2002:aa7:d748:: with SMTP id a8mr63669081eds.21.1639394169212; Mon, 13 Dec 2021 03:16:09 -0800 (PST) Received: from kostyanf14nb.Dlink ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id a13sm6139384edk.29.2021.12.13.03.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 03:16:08 -0800 (PST) From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Michael Roth , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 4/5] gqa-win: get_pci_info: Replace 'while' with 2 calls of the function Date: Mon, 13 Dec 2021 13:15:53 +0200 Message-Id: <20211213111554.62394-5-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213111554.62394-1-konstantin@daynix.com> References: <20211213111554.62394-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52f (failed) Received-SPF: none client-ip=2a00:1450:4864:20::52f; envelope-from=konstantin@daynix.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Microsoft suggests this solution in the documentation: https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupdigetdeviceinterfacedetaila Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index cef14a8762..6bde5260e8 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -552,10 +552,10 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) if (SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, &GUID_DEVINTERFACE_DISK, 0, &dev_iface_data)) { - while (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, - pdev_iface_detail_data, - size, &size, - &dev_info_data)) { + if (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, + pdev_iface_detail_data, + size, &size, + &dev_info_data)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { pdev_iface_detail_data = g_malloc(size); pdev_iface_detail_data->cbSize = @@ -567,6 +567,16 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } } + if (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, + pdev_iface_detail_data, + size, &size, + &dev_info_data)) { + // pdev_iface_detail_data already is allocated + error_setg_win32(errp, GetLastError(), + "failed to get device interfaces"); + goto cleanup; + } + dev_file = CreateFile(pdev_iface_detail_data->DevicePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); @@ -597,8 +607,8 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) ULONG dev_id_size = 0; size = 0; - while (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, - parent_dev_id, size, &size)) { + if (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, + parent_dev_id, size, &size)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { parent_dev_id = g_malloc(size); } else { @@ -608,6 +618,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } } + if (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, + parent_dev_id, size, &size)) { + // parent_dev_id already is allocated + error_setg_win32(errp, GetLastError(), + "failed to get device instance ID"); + goto cleanup; + } + /* * CM API used here as opposed to * SetupDiGetDeviceProperty(..., DEVPKEY_Device_Parent, ...) From patchwork Mon Dec 13 11:15:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 12673753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0BA89C433F5 for ; Mon, 13 Dec 2021 11:21:05 +0000 (UTC) Received: from localhost ([::1]:38432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwjOC-0005bc-0I for qemu-devel@archiver.kernel.org; Mon, 13 Dec 2021 06:21:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwjJV-0008WF-VO for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:15 -0500 Received: from [2a00:1450:4864:20::531] (port=43549 helo=mail-ed1-x531.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwjJT-0007Fz-Gd for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:13 -0500 Received: by mail-ed1-x531.google.com with SMTP id o20so51234304eds.10 for ; Mon, 13 Dec 2021 03:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ahhw9F7FEinJ7VZiCiD3/+4+Y4DOuDMMwasuLCf6UN0=; b=YqCKeXmmTy8qs3Wv2aSbGTmUGiyPPwEk2J0Zyiv5jBA0czawUgt2KGcfQefhG2mvwc z/62GytR5kWw03mVQE1Ynmlc30WPh9QCpjqUT5Oy5FY/bWDfl3qaJ2akRP2DEqLa7EFk yFs27pZPhwr0Liurndf81F89HyLAT0WVz/STnuBwkMpzyPIWosaX9xkuOKtkqRRg3oTt /wQWgIsmaZ7mB/omZumM8+7iKcMM0NwuKLDmvoes8Sx4tAR9VGlztE1PSax6INqzWZp9 DENXFHdKvYmaZ1ufKy7dOC4Ya2wo5I1SJXQCv7V+xMT5UAskRj9v5N6MZaS9Jw8S9ivG 6LAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ahhw9F7FEinJ7VZiCiD3/+4+Y4DOuDMMwasuLCf6UN0=; b=oPjTJzAfbgv/abRytc3UuXOuOvhOtfPGSXmemuLwz6qDHKK1igcGP9i+Ey6dOWbgky Az1+eBaCpNS9p75zPtRggzo7jY4y47QXcOvh93fuRpJzvVKvpqPd3N4yWrM7BlvAKsjj /qGtHprfoCn1JbGEBpWO79NdiSXqt5xuAffR7sauzLM8E8ns5/93tHtotp8va75qR4U8 6xmGnhDt0v2O3F7ocYkCzDp9beOwvbxYhsXL5ILNIkLCG6UZcafnYAh06TsQ5klsQ7bt qp5Zfs3fVRyU481R/QmCZ8o54MT6LFMbRylLGCGm1/z9dvd13rAUMdlTTO24pgJwh+Ci U1UA== X-Gm-Message-State: AOAM533afP/go1wk253vFU6TTM1Jnide3m+dqIwZwxMdXqhk9g9yeiNz eEW+LEKZA38LYtBFBc3K8Rb6qh/ybQZCFw== X-Google-Smtp-Source: ABdhPJwLJ9XPvD/vgZyDGkiARsmNhVaYIQFvJ7wQBvfFsXg6SIUpEnPY9galYbuMO5nSXJpzHh3SAg== X-Received: by 2002:a50:da48:: with SMTP id a8mr63232311edk.155.1639394170115; Mon, 13 Dec 2021 03:16:10 -0800 (PST) Received: from kostyanf14nb.Dlink ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id a13sm6139384edk.29.2021.12.13.03.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 03:16:09 -0800 (PST) From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Michael Roth , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 5/5] gqa-win: get_pci_info: Add g_autofree for few variables Date: Mon, 13 Dec 2021 13:15:54 +0200 Message-Id: <20211213111554.62394-6-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213111554.62394-1-konstantin@daynix.com> References: <20211213111554.62394-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::531 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::531; envelope-from=konstantin@daynix.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 6bde5260e8..96737f33e1 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -541,9 +541,9 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); dev_iface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) { - PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL; + g_autofree PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL; STORAGE_DEVICE_NUMBER sdn; - char *parent_dev_id = NULL; + g_autofree char *parent_dev_id = NULL; SP_DEVINFO_DATA parent_dev_info_data; DWORD j; DWORD size = 0; @@ -580,7 +580,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) dev_file = CreateFile(pdev_iface_detail_data->DevicePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - g_free(pdev_iface_detail_data); if (!DeviceIoControl(dev_file, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &size, NULL)) { @@ -675,7 +674,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) parent_dev_info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_STORAGEPORT, parent_dev_id, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - g_free(parent_dev_id); if (parent_dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(),