qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <anthony@codemonkey.ws>,
	Michael Tokarev <mjt@tls.msk.ru>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Andreas Faerber <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH 2/6] qdev: unref qdev when device_add fails
Date: Tue, 10 Sep 2013 18:21:08 +0200	[thread overview]
Message-ID: <1378830072-28926-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1378830072-28926-1-git-send-email-stefanha@redhat.com>

qdev_device_add() leaks the created qdev upon failure.  I suspect this
problem crept in because qdev_free() unparents the qdev but does not
drop a reference - confusing name.

Also drop trailing whitespace after curly bracket.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 qdev-monitor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 410cdcb..5657cdc 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -512,6 +512,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
     if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
         qdev_free(qdev);
+        object_unref(OBJECT(qdev));
         return NULL;
     }
     if (qdev->id) {
@@ -523,8 +524,9 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         object_property_add_child(qdev_get_peripheral_anon(), name,
                                   OBJECT(qdev), NULL);
         g_free(name);
-    }        
+    }
     if (qdev_init(qdev) < 0) {
+        object_unref(OBJECT(qdev));
         qerror_report(QERR_DEVICE_INIT_FAILED, driver);
         return NULL;
     }
-- 
1.8.3.1

  parent reply	other threads:[~2013-09-10 16:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 16:21 [Qemu-devel] [PATCH 0/6] qdev and blockdev refcount leak fixes Stefan Hajnoczi
2013-09-10 16:21 ` [Qemu-devel] [PATCH 1/6] blockdev: fix drive_init() opts and bs_opts leaks Stefan Hajnoczi
2013-09-10 16:21 ` Stefan Hajnoczi [this message]
2013-09-10 16:49   ` [Qemu-devel] [PATCH 2/6] qdev: unref qdev when device_add fails Paolo Bonzini
2013-09-10 16:59     ` Andreas Färber
2013-09-10 17:04       ` Paolo Bonzini
2013-09-11  5:56       ` Stefan Hajnoczi
2013-09-10 16:21 ` [Qemu-devel] [PATCH 3/6] libqtest: rename qmp() to qmp_discard_response() Stefan Hajnoczi
2013-09-10 16:21 ` [Qemu-devel] [PATCH 4/6] libqtest: add qmp(fmt, ...) -> QDict* function Stefan Hajnoczi
2013-09-10 16:21 ` [Qemu-devel] [PATCH 5/6] blockdev-test: add test case for drive_add duplicate IDs Stefan Hajnoczi
2013-09-10 16:21 ` [Qemu-devel] [PATCH 6/6] qdev-monitor-test: add device_add leak test cases Stefan Hajnoczi

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=1378830072-28926-3-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=afaerber@suse.de \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=pbonzini@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).