All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zheng Huang <hz1624917200@gmail.com>
To: mst@redhat.com
Cc: qemu-devel@nongnu.org, hz1624917200@gmail.com
Subject: [PATCH] virtio-pci: fix memory leak from device realization failure
Date: Fri, 28 Feb 2025 13:03:27 +0800	[thread overview]
Message-ID: <69cb6f19-d87a-4ddf-9fca-612b30828679@gmail.com> (raw)
In-Reply-To: <7702b335-6e92-47c7-baf9-a384f75a0db3@gmail.com>

This commit adds failback routine for `virtio_pci_realize` to 
fix the memory leak of an address space and the virtio-net device object.
If the realization of the device failed, the address space should be 
destroyed too.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2845

Signed-off-by: Zheng Huang <hz1624917200@outlook.com>

---
 hw/virtio/virtio-pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index c773a9130c..4b0d8cd90a 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2266,6 +2266,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
     virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy);
     if (k->realize) {
         k->realize(proxy, errp);
+        if (*errp) {
+            address_space_destroy(&proxy->modern_cfg_mem_as);
+        }
     }
 }
 
-- 
2.34.1




       reply	other threads:[~2025-02-28  5:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7702b335-6e92-47c7-baf9-a384f75a0db3@gmail.com>
2025-02-28  5:03 ` Zheng Huang [this message]
2025-02-28  9:24   ` [PATCH] virtio-pci: fix memory leak from device realization failure Philippe Mathieu-Daudé
2025-03-03  7:41     ` Zheng Huang
2025-03-10  9:04     ` Zheng Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69cb6f19-d87a-4ddf-9fca-612b30828679@gmail.com \
    --to=hz1624917200@gmail.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.