From nobody Sat Nov 15 17:22:41 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.com; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1749804721; cv=none; d=zohomail.com; s=zohoarc; b=B46At5BP9CjmB0eJlns/cfa0Vvtsc2N2u2JoaSDFp+2QUvx1i2khENShfH6RuJ3rZuA/lR3M2CiKefokQhNsfcO5w8yU9vC4dewmmh8x81WVa74Y2IozqpoyR4WLh9FFCTAasXtbcHMEsxfJjs3BuPIs7ylIrEqUdKmiMUHg1co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749804721; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=SVoFmrEL7sdTxB0RuF5waTeR+x+vV9gCNV2idXFHSCs=; b=MZHhbPudob2ENM5hWTRiMO1fw2ZsZWLy2pCGaQFv5I6599/e2f0Ff2MpuAFdDnlZ4ESPZGxVK/4wf1avazMCopDVt9kL5Yvj67jzotjlKKWZ0eY+WYOXyMzO4p04pCqoZumVwwqPcFl0RGRrU8Wxt0dsE8TOdE0B21SeyTAeaOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.com; 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 1749804721744671.4004551424773; Fri, 13 Jun 2025 01:52:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ08O-00007N-8E; Fri, 13 Jun 2025 04:51:36 -0400 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 1uQ08N-00007C-9g for qemu-devel@nongnu.org; Fri, 13 Jun 2025 04:51:35 -0400 Received: from esa11.hc1455-7.c3s2.iphmx.com ([207.54.90.137]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ08L-0008Q3-4a for qemu-devel@nongnu.org; Fri, 13 Jun 2025 04:51:34 -0400 Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2025 17:51:29 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 27AFBD5004 for ; Fri, 13 Jun 2025 17:51:27 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id B648BE6475 for ; Fri, 13 Jun 2025 17:51:26 +0900 (JST) Received: from iaas-rpma.. (unknown [10.167.135.44]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 4AE131A006C; Fri, 13 Jun 2025 16:51:24 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1749804693; x=1781340693; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+3TOcpTxi9mK4IV8I/nyRY5m6fVt28OeBORAHhi1yqs=; b=qzaZB+S70zRTcYt4MzZsjZ0Uuk1YE0Mfqd1NhlxTPMDtxX6rdQiPbIY2 Jd7A9IZwwZezQ5ynelO3pmzddY/21eMSXTlrrsZIpka6P8FNRh+2b5F6F ibMtHv9lB+sqeqzCRacx7yo4pgAdymn33fnbs5OEefrUynL4nwgd9gODC Tep9n8h/ZJIMI8f4m2lVpAdLqWh38R3I+1veGymWyx18LIFD4uUMc++VR RBZanYZIYf76PbWU5TyVQi1vEAFdVP3b6pBapjfB8+00BNp3J/36ew/bn sA0nkCoFXf2jL81BieEQaDND9zIO9tQJ0wphsggqMmeoxqdlcGbLDf5iW A==; X-CSE-ConnectionGUID: uZrpzOvkSsuRwwzw0ogF/A== X-CSE-MsgGUID: qdD6QnkXScK0kE34X3e5/g== X-IronPort-AV: E=McAfee;i="6800,10657,11462"; a="182124110" X-IronPort-AV: E=Sophos;i="6.16,233,1744038000"; d="scan'208";a="182124110" To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, mst@redhat.com, anisinha@redhat.com, Li Zhijian , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH v2] hw/acpi: Fix GPtrArray memory leak in crs_range_merge Date: Fri, 13 Jun 2025 16:51:10 +0800 Message-Id: <20250613085110.111204-1-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=207.54.90.137; envelope-from=lizhijian@fujitsu.com; helo=esa11.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Li Zhijian From: Li Zhijian via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749804722857116600 This leak was detected by the valgrind. The crs_range_merge() function unconditionally allocated a GPtrArray 'even when range->len was zero, causing an early return without freeing the allocated array. This resulted in a memory leak when an empty range was processed. Instead of moving the allocation after the check (as previously attempted), use g_autoptr for automatic cleanup. This ensures the array is freed even on early returns, and also removes the need for the explicit free at the end of the function. Signed-off-by: Li Zhijian Reviewed-by: Ani Sinha Reviewed-by: Daniel P. Berrang=C3=A9 --- Cc: Daniel P. Berrang=C3=A9 Cc: Ani Sinha Ani Sinha, I didn't pick your Reviewed-by tag since V2 changes the proposal. Please take another look. V2: - use g_autoptr for automatic cleanup # Suggested by Daniel --- hw/acpi/aml-build.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index f8f93a9f66c8..cb817a0f31f1 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -160,7 +160,7 @@ void crs_replace_with_free_ranges(GPtrArray *ranges, */ static void crs_range_merge(GPtrArray *range) { - GPtrArray *tmp =3D g_ptr_array_new_with_free_func(crs_range_free); + g_autoptr(GPtrArray) tmp =3D g_ptr_array_new_with_free_func(crs_range_= free); CrsRangeEntry *entry; uint64_t range_base, range_limit; int i; @@ -191,7 +191,6 @@ static void crs_range_merge(GPtrArray *range) entry =3D g_ptr_array_index(tmp, i); crs_range_insert(range, entry->base, entry->limit); } - g_ptr_array_free(tmp, true); } =20 static void --=20 2.47.0