From patchwork Tue Oct 1 16:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 831879 Delivered-To: patch@linaro.org Received: by 2002:a5d:43d2:0:b0:367:895a:4699 with SMTP id v18csp383268wrr; Tue, 1 Oct 2024 09:40:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWaMLZC39CVNDnzQruuO6Gk6nNzFWTEYVAKToZlarpL1+kS/aUmouCpGaWofZJgNzJ1cvXGLg==@linaro.org X-Google-Smtp-Source: AGHT+IGDp7LIEDZ+QNrM11BY7aCr6EN+6P0NHmjwneDEJxCr5gcaVvihwF8UfZApW0fyGtZ51OFw X-Received: by 2002:a05:6358:7f12:b0:1b3:9b15:ac01 with SMTP id e5c5f4694b2df-1c0cecdd8cdmr68945655d.3.1727800819895; Tue, 01 Oct 2024 09:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727800819; cv=none; d=google.com; s=arc-20240605; b=FfXC5pWPoV/kQrkawDxxW39+NdsaU/pdyYxAWCuf/Ig/Aclx2hynCBfSN+kyLYR/SO Ooqjyl3gszJfcUGyoBEJWeiFGq7au/qmsiU861ElLA022Wb7b+tb6OyEwrlWIgubXTc+ V9D5RHn/lcfHo60QVwRYX0iMx0t78qk3ZnxHcYNcSi8vVQwqQ5Qxs/f4n/MpbQsePEZL UAsPiDri5YqWISIXDN/cgMab7gqFLYNpnJUOKEXv5jfYYfjObVvQfSPWAVEKuqKSKw3f NHtlJjCKEi8+4ByeY9mdt2kUnNPNmWSuBXPE1Qd8H1remv9PZ5MnBAk4MPAzasotZDdp m8Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=DD9Jh8+RmgvZlCMgMoDzKAAVACdceEVcyQEeEUMmaT4=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=MoPPEN1pvBzKZf0W1hodyVguGkFFpsicvkscmdYLlzKg25Yd1V1JjL3E8oq+yqnUZ2 NzpXfNZyUIRo8gP7e4LgJFf2s0uYfEnPyB2amt97tigC0uaWaFyf9MBQmgGEVbffXUzE u41xKnSWC8e+I4O7kjCIVAcgvoC5YV6qzDG9q/ijqPhAFtQAlG3LeSg5KRc6+GqFXuJZ VX/Jm2DbEaij2qX39IuhUBYiAaAKew00KKVc+/p+1fXgfDJzyJfCs2c//Sa0rLQFnk09 R5vYP7FWylC4nP6h+bYoewh5uJ9XCitwoTpJH3yT5Z2q7E8Y+ImzkTJSvuAtR2SbvFyh sBmQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MvsrVk8s; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45c9f3a0287si119574481cf.740.2024.10.01.09.40.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Oct 2024 09:40:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MvsrVk8s; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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_mathbern@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); } +static void init_irq_fields(IRQState *irq, qemu_irq_handler handler, + void *opaque, int n) +{ + irq->handler = handler; + irq->opaque = opaque; + irq->n = n; +} + void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque, int n) { object_initialize(irq, sizeof(*irq), TYPE_IRQ); - irq->handler = handler; - irq->opaque = opaque; - irq->n = n; + init_irq_fields(irq, handler, opaque, n); } qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler, @@ -66,11 +72,8 @@ qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n) qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n) { - IRQState *irq; - - irq = g_new(IRQState, 1); - qemu_init_irq(irq, handler, opaque, n); - + IRQState *irq = IRQ(object_new(TYPE_IRQ)); + init_irq_fields(irq, handler, opaque, n); return irq; }