From nobody Sun Nov 24 02:33:54 2024 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=1727800820; cv=none; d=zohomail.com; s=zohoarc; b=P0q1vuIUBtzZ/R15G6HEenOFk4+8vwYYbXB4pzGybtFN/lO019pQ5tlusB9kHZmWf2cDwmBhcs4Fz+wrzvaltC4i46gT5sxN5m9gh20LBpu1iGTyElXGSTV0p9lQgmFxID+r2u3eEiFwqPGdkn0wGiLW2L2ZnyOggSRkyt5uP0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727800820; h=Content-Transfer-Encoding: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:Cc; bh=DD9Jh8+RmgvZlCMgMoDzKAAVACdceEVcyQEeEUMmaT4=; b=GQuT2BWD95sdrz1VgCARrhj/PfdmO9X086E0uw2AKPF9GwpWqoWfYUTe5A4mosg6tUI2op5j+LPZi5jFi+/PcyX5/4rWJB5Nytv+1aTH0ocQ9RoWXmNfxfxa3sDwyCADuzYict85D9deUFlEpV5N8x6VaBghBNeBvsLtI3XTiOU= 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 1727800820258529.4730032391636; Tue, 1 Oct 2024 09:40:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svfuJ-0005Iy-RH; Tue, 01 Oct 2024 12:39:27 -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 1svfuI-0005I8-G8 for qemu-devel@nongnu.org; Tue, 01 Oct 2024 12:39:26 -0400 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 1svfuG-00060X-VH for qemu-devel@nongnu.org; Tue, 01 Oct 2024 12:39:26 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42e7b7bef42so47240145e9.3 for ; Tue, 01 Oct 2024 09:39:24 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e6547sm12243771f8f.58.2024.10.01.09.39.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727800763; x=1728405563; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=DD9Jh8+RmgvZlCMgMoDzKAAVACdceEVcyQEeEUMmaT4=; b=MvsrVk8sjNuov87V/95rCAWH9rBRa9tGy4Gya7Kc8BVXaM1hlGHykWwEEbY1EgS3QE OYdODpZi/d2g/jDyqS1TF61Xty3jMKS7jH+zdOXXyTulY6LDer6+3ONfzM6QlXE3iDAW TLjnBmAhIFhup3t/b7p8NW7XIbjfwLv754z01Jp1OgzCJA5DObfV9Tzbc//CCAJAOK/Q qjx+8PR9ld515vCY2oVhvKIyJo5GpkMnbeuktnQ1c6iXQulugqrU5axywSRQsoU5Hhfv QdDQzHFGGuA4FYmCN3ziY6797obguuexixtTT2ybsObLGS7rOUZz2scdAgQIzlMCQEZu CWUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727800763; x=1728405563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DD9Jh8+RmgvZlCMgMoDzKAAVACdceEVcyQEeEUMmaT4=; b=h4RPuhHB4TJAkVpVCwGU3eXN3OKsd0/EDoeKt2+0JE8+DeChD/0MTCXcPl0/zH1yJF nATbUBCBUzuVKN5YwqoXta68z/Dhlg4QEqi8V9NLzNJzE2SSx2NNueY7eMEOs9ydz0x2 ITthbx1t8TF0MZtoMGpVNBvlLoSvjzenK1qkbgMkYSWMMbau9K4zi6zv+fWgV22aJWEI 0K3+gc5wZeQTUSJvwYUq/xxhdN7L+Sr0s0XXXjSCwVZrPIk3Mmoqm2LxZbXbtKO83axF /bVKdNvLEdJnTDLXe2w2fEG4NAYSd1MD5UNb/XMZzdgHwtfPHfVneqcEcILMfyxLNB6b 5x4g== X-Gm-Message-State: AOJu0YzkelfcP44ey74kzE0TgptKfwnRnyT5Iht5tkvlyjP7aWUKfsHI v7Kr7ee0kkYe+i8ZxrsXfpzOmoi7zBv0y3jYiMb1wv7763wnKonG0IhdUQuEC24xALvyHJrxi9C Q X-Google-Smtp-Source: AGHT+IFKKtPHlneEhOtxU3tkTsIcC2jyr8ssTHo9L3sFDcrHXTpFmELT3TeFolfoI3WjF3lW0QemSA== X-Received: by 2002:a05:600c:310c:b0:42b:af1c:66e with SMTP id 5b1f17b1804b1-42f777b6d0bmr871705e9.9.1727800763235; Tue, 01 Oct 2024 09:39:23 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 06/54] hw: fix memory leak in IRQState allocation Date: Tue, 1 Oct 2024 17:38:30 +0100 Message-Id: <20241001163918.1275441-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001163918.1275441-1-peter.maydell@linaro.org> References: <20241001163918.1275441-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: 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: 1727800821827116600 Content-Type: text/plain; charset="utf-8" From: Matheus Tavares Bernardino At e72a7f65c1 (hw: Move declaration of IRQState to header and add init function, 2024-06-29), we've changed qemu_allocate_irq() to use a combination of g_new() + object_initialize() instead of IRQ(object_new()). The latter sets obj->free, so that that the memory is properly cleaned when the object is finalized, but the former doesn't. Fixes: e72a7f65c1 (hw: Move declaration of IRQState to header and add init = function) Signed-off-by: Matheus Tavares Bernardino Reviewed-by: BALATON Zoltan Reviewed-by: Brian Cain Message-id: 1723deb603afec3fa69a75970cef9aac62d57d62.1726674185.git.quic_ma= thbern@quicinc.com Signed-off-by: Peter Maydell --- hw/core/irq.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/hw/core/irq.c b/hw/core/irq.c index db95ffc18f8..7d5b0038c12 100644 --- a/hw/core/irq.c +++ b/hw/core/irq.c @@ -34,13 +34,19 @@ void qemu_set_irq(qemu_irq irq, int level) irq->handler(irq->opaque, irq->n, level); } =20 +static void init_irq_fields(IRQState *irq, qemu_irq_handler handler, + void *opaque, int n) +{ + irq->handler =3D handler; + irq->opaque =3D opaque; + irq->n =3D n; +} + void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque, int n) { object_initialize(irq, sizeof(*irq), TYPE_IRQ); - irq->handler =3D handler; - irq->opaque =3D opaque; - irq->n =3D n; + init_irq_fields(irq, handler, opaque, n); } =20 qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler hand= ler, @@ -66,11 +72,8 @@ qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, v= oid *opaque, int n) =20 qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n) { - IRQState *irq; - - irq =3D g_new(IRQState, 1); - qemu_init_irq(irq, handler, opaque, n); - + IRQState *irq =3D IRQ(object_new(TYPE_IRQ)); + init_irq_fields(irq, handler, opaque, n); return irq; } =20 --=20 2.34.1