]> git.proxmox.com Git - mirror_qemu.git/commit
qom/object: Add a new function object_initialize_child()
authorThomas Huth <thuth@redhat.com>
Mon, 16 Jul 2018 12:59:18 +0000 (14:59 +0200)
committerPeter Maydell <peter.maydell@linaro.org>
Tue, 17 Jul 2018 12:12:49 +0000 (13:12 +0100)
commit0210b39d0e84d5a63a3e468f177c07a3a98d88a8
tree8acaf4927bd6987ef245c7a3c35214bfac9a860c
parent3e86907c822c0d7e6f9a4476a5b234a60f6adcf2
qom/object: Add a new function object_initialize_child()

A lot of code is using the object_initialize() function followed by a call
to object_property_add_child() to add the newly initialized object as a child
of the current object. Both functions increase the reference counter of the
new object, but many spots that call these two functions then forget to drop
one of the superfluous references. So the newly created object is often not
cleaned up correctly when the parent is destroyed. In the worst case, this
can cause crashes, e.g. because device objects are not correctly removed from
their parent_bus.

Since this is a common pattern between many code spots, let's introduce a
new function that takes care of calling all three required initialization
functions, first object_initialize(), then object_property_add_child() and
finally object_unref(). And since the function does a similar job like
object_new_with_props(), also allow to set additional properties via
varargs, and use user_creatable_complete() to make sure that the functions
can be used similarly.

And while we're at object.h, also fix some copy-n-paste errors in the
comments there ("to store the area" --> "to store the error").

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Message-id: 1531745974-17187-2-git-send-email-thuth@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
include/qom/object.h
qom/object.c