From: Anthony Liguori <aliguori@us.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Liu Ping Fan <qemulist@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 1.3 1/5] qom: fix refcount of non-heap-allocated objects
Date: Mon, 26 Nov 2012 09:49:01 -0600 [thread overview]
Message-ID: <87ehjgpdoy.fsf@codemonkey.ws> (raw)
In-Reply-To: <1353660436-8897-2-git-send-email-pbonzini@redhat.com>
Paolo Bonzini <pbonzini@redhat.com> writes:
> The reference count for embedded objects is always one too low, because
> object_initialize_with_type returns with zero references to the object.
> This causes premature finalization of the object (or an assertion failure)
> after calling object_ref to add an extra reference and object_unref to
> remove it.
>
> The fix is to move the initial object_ref call from object_new_with_type
> to object_initialize_with_type.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> qom/object.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index d7092b0..6a8c02a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -307,6 +307,7 @@ void object_initialize_with_type(void *data, TypeImpl *type)
>
> memset(obj, 0, type->instance_size);
> obj->class = type->class;
> + object_ref(obj);
> QTAILQ_INIT(&obj->properties);
> object_init_with_type(obj, type);
> }
But object_property_add_child() will take a reference.
When the parent object goes away, this will cause that reference to get
dropped and ultimately the child object to be destroyed.
IOW, this change causes embedded objects to get leaked AFAICT.
Regards,
Anthony Liguori
> @@ -395,7 +396,6 @@ Object *object_new_with_type(Type type)
>
> obj = g_malloc(type->instance_size);
> object_initialize_with_type(obj, type);
> - object_ref(obj);
>
> return obj;
> }
> --
> 1.8.0
next prev parent reply other threads:[~2012-11-26 15:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-23 8:47 [Qemu-devel] [PATCH 1.3 0/5] QOM/qdev lifetime fixes Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 1/5] qom: fix refcount of non-heap-allocated objects Paolo Bonzini
2012-11-23 16:49 ` Andreas Färber
2012-11-26 15:49 ` Anthony Liguori [this message]
2012-11-26 16:08 ` Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 2/5] qdev: move bus removal to object_unparent Paolo Bonzini
2012-11-23 16:52 ` Andreas Färber
2012-11-27 1:02 ` Andreas Färber
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 3/5] qom: make object_delete usable for statically-allocated objects Paolo Bonzini
2012-11-23 17:02 ` Andreas Färber
2012-11-23 17:10 ` Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses Paolo Bonzini
2012-11-23 17:07 ` Andreas Färber
2012-11-23 17:16 ` Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 5/5] qom: make object_finalize static Paolo Bonzini
2012-11-23 17:12 ` Andreas Färber
2012-11-23 17:32 ` Paolo Bonzini
2012-11-26 21:47 ` [Qemu-devel] [PATCH 1.3 0/5] QOM/qdev lifetime fixes Anthony Liguori
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=87ehjgpdoy.fsf@codemonkey.ws \
--to=aliguori@us.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@gmail.com \
/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).