From nobody Sat Apr 11 23:08:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1772727405; cv=none; d=zohomail.com; s=zohoarc; b=hr/zA/wlb2tROJeJ3hOs5goXSmDsXRdPtOdJrPcGcx5hO41uWLkan0TYZCyHU7eLMjw+JRCedOHuypt5AfUL8b2pf2EJskgBfwOeD03Krb2q3vwx3ynSnwRsxxf9g7NVawZj5TBHbp5cidkfGBHPgrWi/KT2UiL17JpEZMpTckA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772727405; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=66f14nHgF3hsPxrBBUn4yi70/4pZ5+fvKw9BgRnowjE=; b=Nsi7BZp0UnMhfZy6NWyp+zLiL8vFwlGvfdJh2gF/WgHoCydSjMD43EiHFua6RvjL3GKMhjKXhQzMH80Q2zUGfcoWNzXekLSLveIE5NFtvl2t64i07itQ+3v9VUK93su0jkG7uoPjlovz/Pjs7YuPVzo4KcAfB/zgSOt66MCTe0w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772727405392766.7744029656016; Thu, 5 Mar 2026 08:16:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyBMb-00089n-LP; Thu, 05 Mar 2026 11:15:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyBMS-00088Q-Nc for qemu-devel@nongnu.org; Thu, 05 Mar 2026 11:15:43 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vyBMP-0004Wi-Kh for qemu-devel@nongnu.org; Thu, 05 Mar 2026 11:15:39 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4836e3288cdso55302155e9.0 for ; Thu, 05 Mar 2026 08:15:37 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4851fad01d2sm53466465e9.3.2026.03.05.08.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 08:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772727336; x=1773332136; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=66f14nHgF3hsPxrBBUn4yi70/4pZ5+fvKw9BgRnowjE=; b=yh5M28cbnQVrp/wkm1WVb4mY9i+CuZAbREB35P/j8sDWPevq2itKkCc1IV6e1hYh4/ 93U3mS1DmUWLwLNth7xc1WDTBtlPqOn9Fwxf/11yNgfjWOVBX51HA9JlsEb80Ou84fHP 5r4/v7g5paGlGz7mw6KlPySbWN+uD3JDpzODPc5g12Mi3TQfWVvQQNG+1q5qx9LmYcCt TTX2PyHiTcqgYjnECF6JaOx2vHDBKRr3qiNv3lTHAdT1EAc/LZpzf1ldw7VWZEn9nurj bFqh+/LfudU5O12T/OClxaHIMxz6mr4qm8ArX7Y+xBIAlUrdHMqdJoLe0KZjeU+cCFtT 44vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772727336; x=1773332136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=66f14nHgF3hsPxrBBUn4yi70/4pZ5+fvKw9BgRnowjE=; b=flb9CQ1J+Vnd5QFHsVor1H39pPtGR6272cnqtsMNLPdLX21g+Bv0/3eUZzrx5w3nn9 yxOmEgDo2Sw7KXa2MPkbsqPSFohgey05XZk5IVQ0hvo84HII8nzUBmjbo8T26xhsg5xb PKGMcbzWeqV3S8H0Zxy+MXqIuBPxw+MlV1q0rGbh2arNvJAnWGN3WN6ImFGrG6ykeShV eVSBbvh2tiIMnisKstV+aM/fOC2rT+tQL1RrfWCg2jML3QADrypXGQZHgQ1cXCYrvshX n694xO82p6DJDOu84KgI9L2xO0xbIsYUriPM+6fzllZmDOilzJEDq5yemsnFbZrdlMyH Vbkg== X-Gm-Message-State: AOJu0YwT7GZ3aTVpUR87Mle5rz7dw350BU9b/4MkQdiFExmNsJvrV+q0 2LgQsaxHLqUINhplt5kUXgkIwAWJpFYlKv0C1JPaOyX25tFCFvKUx2D358DzdSJHQ4rmOJZHc2l oxybH X-Gm-Gg: ATEYQzw4F4SMI3/7rBFXgMfGGGHJJlZMRimzFqBtSZ/HWEZTrWwYMIcybSFv+PWrELu IvhJfWE/+qFeWx7EqxMoxfdW/XSmTQJ6yE0ATBQWvRCr0jOPpFu2LweQkT16ye4GH1H92vgKIq1 PSENFdb4rvg+yfe07+YwCH6TYt3FPBOU/jR6k2rSOrTQuECNFGtZeCs4MlVfk3uIcHMdNd5yIwK 5OKJAsW1XDB2lkYRrnDh5BiftrC+DsGtuaaAYfcaE3X8OE/DJO0w88PkWuTOI5EIKbY3KyRh1xD Xne0PrJB/V+cJ3GY+wbOe4ygkyea9z/zxX5u+2LBgp4btAWy4c5NhC70tuMEnztmIjhepzLp+bN w7wxoi2XsO/RYDdzLqbNK6CBSgjNNFE/frSap8yXBb4Bl9tpvgtx8+6kdran39dsExulhx7Czks py8lqmfYCUgLx4hlayObHQl8r0uH1/XnqGek1fU5UgLP3yjOAZVfeZxmy3skN0IRLQ9Z5cy7BHE rENdlsoeIBQyeIdr/RK1h3RulN6AwQ= X-Received: by 2002:a05:600c:8189:b0:483:4b37:8620 with SMTP id 5b1f17b1804b1-4851ee91f1emr45938655e9.10.1772727335989; Thu, 05 Mar 2026 08:15:35 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH 2/3] tests/tcg/plugins/mem: Correct hash iteration code in plugin_exit() Date: Thu, 5 Mar 2026 16:15:30 +0000 Message-ID: <20260305161531.1774895-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260305161531.1774895-1-peter.maydell@linaro.org> References: <20260305161531.1774895-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1772727406289158500 Content-Type: text/plain; charset="utf-8" In plugin_exit() we call g_hash_table_get_values() to get a GList which we look at to print some information. This code has multiple issues: * it names the local variable for the GList "count", which shadows the "qemu_plugin_scoreboard *count". This isn't incorrect, but it is unnecessarily confusing * it doesn't free the list, and the leak sanitizer complains: Indirect leak of 2328 byte(s) in 97 object(s) allocated from: #0 0x5589b0b72293 in malloc (/home/pm215/qemu/build/x86-tgt-san/qemu-sy= stem-i386+0x1a2f293) (BuildId: 26964cad9e3f81d35fc144d7cc88b53adf6f60c7) #1 0x78fd8cfa1ac9 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0= x62ac9) (BuildId: 116e142b9b52c8a4dfd403e759e71ab8f95d8bb3) #2 0x78fd8cf96e4a in g_list_prepend (/lib/x86_64-linux-gnu/libglib-2.0.= so.0+0x57e4a) (BuildId: 116e142b9b52c8a4dfd403e759e71ab8f95d8bb3) #3 0x78fd8cf8b318 in g_hash_table_get_values (/lib/x86_64-linux-gnu/lib= glib-2.0.so.0+0x4c318) (BuildId: 116e142b9b52c8a4dfd403e759e71ab8f95d8bb3) #4 0x78fd84d1a90c in plugin_exit /home/pm215/qemu/build/x86-tgt-san/../= ../tests/tcg/plugins/mem.c:87:25 * in iterating through the list it updates "count", so by the time we get to the end of the loop we no longer have a pointer to the head of the list that we could use to free it * it checks for the list being NULL twice (once in an if() and once in the for() loop's "while" condition), which is redundant * it skips the loop if g_list_next(counts) is NULL, which means it will wrongly skip the loop if the list has only one entry Rewrite the iteration code to fix these problems. Signed-off-by: Peter Maydell Reviewed-by: Pierrick Bouvier --- I am assuming that not printing the region info when there is exactly one region is a mistake, but perhaps it is intentional? tests/tcg/plugins/mem.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index f3992abc8f..1ee257f855 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -84,24 +84,22 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) =20 =20 if (do_region_summary) { - GList *counts =3D g_hash_table_get_values(regions); + g_autoptr(GList) regionlist =3D g_hash_table_get_values(regions); =20 - counts =3D g_list_sort_with_data(counts, addr_order, NULL); + regionlist =3D g_list_sort_with_data(regionlist, addr_order, NULL); =20 g_string_printf(out, "Region Base, Reads, Writes, Seen all\n"); =20 - if (counts && g_list_next(counts)) { - for (/* counts */; counts; counts =3D counts->next) { - RegionInfo *ri =3D (RegionInfo *) counts->data; + for (GList *l =3D regionlist; l; l =3D g_list_next(l)) { + RegionInfo *ri =3D (RegionInfo *) l->data; =20 - g_string_append_printf(out, - "0x%016"PRIx64", " - "%"PRId64", %"PRId64", %s\n", - ri->region_address, - ri->reads, - ri->writes, - ri->seen_all ? "true" : "false"); - } + g_string_append_printf(out, + "0x%016"PRIx64", " + "%"PRId64", %"PRId64", %s\n", + ri->region_address, + ri->reads, + ri->writes, + ri->seen_all ? "true" : "false"); } qemu_plugin_outs(out->str); } --=20 2.43.0