From nobody Sat Nov 15 17:21:15 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=1749789685; cv=none; d=zohomail.com; s=zohoarc; b=CJ370/LKJexGdjD1+fYniKXg3lnie4SGAcVkqgk3PUNjEDqZ3AlWKgNBsHAA8XWs3ObUEUc8TaDcP7kZxT8GNMx8GdJgZ57m3KXhvhbmC21Q4E6wtwE/7icP/Cqq6oQRjBWjtEAF7hwJw62qJFQsrfhgNnak75aligUllRedyNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749789685; h=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=Fhowb9Sn9t1pdSJjZJD+M8uMA1cFbF5E4mawnj+tuxw=; b=Pne5VAIWtm5nZgKqqFODrtEtjI3Ipgi/AvPKKNt10lQIGkQaqkcbEExacuvDNU25PGurbZjti0Dr+j6ka7tA4Wnx39LHonXpj4t9GKlKDUhdWjsHad0DY2zLt0hDtfwY17Ezty4C0RI49TqEDl6iIVgHGq+TlU9iOzILUx7r058= 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 174978968558117.583045603181176; Thu, 12 Jun 2025 21:41:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPwDS-0004xn-On; Fri, 13 Jun 2025 00:40:35 -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 1uPwDP-0004xc-QC for qemu-devel@nongnu.org; Fri, 13 Jun 2025 00:40:32 -0400 Received: from esa3.hc1455-7.c3s2.iphmx.com ([207.54.90.49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPwDB-0004Nz-HK for qemu-devel@nongnu.org; Fri, 13 Jun 2025 00:40:20 -0400 Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2025 13:40:12 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 948A3E9E80 for ; Fri, 13 Jun 2025 13:40:09 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 384F3D4C03 for ; Fri, 13 Jun 2025 13:40:09 +0900 (JST) Received: from iaas-rpma.. (unknown [10.167.135.44]) by edo.cn.fujitsu.com (Postfix) with ESMTP id C1C3D1A0071; Fri, 13 Jun 2025 12:40:07 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1749789618; x=1781325618; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ArXwXdTlXKYXVQXJTgffx5QFKi4535Xey/oWW31JuzI=; b=RWq8HzJB1epGGQ7Myfd3+lFeCdYyZFhV58cxUSptz68W+ZGQsL6ARWTR 0O/KbQ3izK5TH1CLzu320HoA8QWllKLex+lKgYDxYwvQlprDEAIIvJ1oL pDxhj6bT6n7EgkwSh2bsBy/I/o3zeJhdGF5resOKMUNyQqis00ZWWP6Xs XBvN5tAG/4k0tvkSWg1qSsu/L/LiAxVVeoKDLjX1O2FkrdqiTi7at47jK leS0zmwREgJJyypXZh39xReeqOUAnSDvL4DeGAgetQGhPmWiTWJyJAfJH ACqky8VXQwKIavE1iwZMfdkM1NTJaLKdN9xCl2ZUUqDlE0mslsmx+uDlO w==; X-CSE-ConnectionGUID: enyDLMJPQaOy3gfLraPgLQ== X-CSE-MsgGUID: 3XLF9/5wRvq1+TkGj/mCpA== X-IronPort-AV: E=McAfee;i="6800,10657,11462"; a="202577964" X-IronPort-AV: E=Sophos;i="6.16,232,1744038000"; d="scan'208";a="202577964" To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, mst@redhat.com, anisinha@redhat.com, Li Zhijian Subject: [PATCH] hw/acpi: Fix GPtrArray memory leak in crs_range_merge Date: Fri, 13 Jun 2025 12:40:02 +0800 Message-Id: <20250613044002.106396-1-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.31.1 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=207.54.90.49; envelope-from=lizhijian@fujitsu.com; helo=esa3.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: 1749789687543116600 Content-Type: text/plain; charset="utf-8" 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. Fix this by moving the GPtrArray allocation after the empty range check, ensuring memory is only allocated when actually needed. Signed-off-by: Li Zhijian Reviewed-by: Ani Sinha --- hw/acpi/aml-build.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index f8f93a9f66c8..cf1999880119 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); + GPtrArray *tmp; CrsRangeEntry *entry; uint64_t range_base, range_limit; int i; @@ -169,6 +169,7 @@ static void crs_range_merge(GPtrArray *range) return; } =20 + tmp =3D g_ptr_array_new_with_free_func(crs_range_free); g_ptr_array_sort(range, crs_range_compare); =20 entry =3D g_ptr_array_index(range, 0); --=20 2.47.0