[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/17] hw/core/qdev-clock: add a reference on aliased clocks
From: |
Paolo Bonzini |
Subject: |
[PULL 04/17] hw/core/qdev-clock: add a reference on aliased clocks |
Date: |
Mon, 26 Oct 2020 09:51:18 -0400 |
From: Luc Michel <luc@lmichel.fr>
When aliasing a clock with the qdev_alias_clock() function, a new link
property is created on the device aliasing the clock. The link points
to the aliased clock and use the OBJ_PROP_LINK_STRONG flag. This
property is read only since it does not provide a check callback for
modifications.
The object_property_add_link() documentation stats that with
OBJ_PROP_LINK_STRONG properties, the linked object reference count get
decremented when the property is deleted. But it is _not_ incremented on
creation (object_property_add_link() does not actually know the link).
This commit increments the reference count on the aliased clock to
ensure the aliased clock stays alive during the property lifetime, and
to avoid a double-free memory error when the property gets deleted.
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Luc Michel <luc@lmichel.fr>
Message-Id: <20201020091024.320381-1-luc@lmichel.fr>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/core/qdev-clock.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
index 6a9a340d0f..eb05f2a13c 100644
--- a/hw/core/qdev-clock.c
+++ b/hw/core/qdev-clock.c
@@ -61,6 +61,14 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev,
const char *name,
object_get_typename(OBJECT(clk)),
(Object **) &ncl->clock,
NULL, OBJ_PROP_LINK_STRONG);
+ /*
+ * Since the link property has the OBJ_PROP_LINK_STRONG flag, the clk
+ * object reference count gets decremented on property deletion.
+ * However object_property_add_link does not increment it since it
+ * doesn't know the linked object. Increment it here to ensure the
+ * aliased clock stays alive during this device life-time.
+ */
+ object_ref(OBJECT(clk));
}
ncl->clock = clk;
--
2.26.2
- [PULL 00/17] Build system changes and misc fixes for QEMU 5.2 soft freeze, Paolo Bonzini, 2020/10/26
- [PULL 03/17] do not use colons in test names, Paolo Bonzini, 2020/10/26
- [PULL 08/17] Makefile: separate meson rerun from the rest of the ninja invocation, Paolo Bonzini, 2020/10/26
- [PULL 04/17] hw/core/qdev-clock: add a reference on aliased clocks,
Paolo Bonzini <=
- [PULL 05/17] qtest: unbreak non-TCG builds in bios-tables-test, Paolo Bonzini, 2020/10/26
- [PULL 02/17] meson: rewrite curses/iconv test, Paolo Bonzini, 2020/10/26
- [PULL 07/17] Remove deprecated -no-kvm option, Paolo Bonzini, 2020/10/26
- [PULL 06/17] replay: do not build if TCG is not available, Paolo Bonzini, 2020/10/26
- [PULL 17/17] machine: move SMP initialization from vl.c, Paolo Bonzini, 2020/10/26
- [PULL 12/17] configure: move install_blobs from configure to meson, Paolo Bonzini, 2020/10/26
- [PULL 15/17] machine: remove deprecated -machine enforce-config-section option, Paolo Bonzini, 2020/10/26
- [PULL 13/17] WHPX: Fix WHPX build break, Paolo Bonzini, 2020/10/26
- [PULL 11/17] configure: remove unused variable from config-host.mak, Paolo Bonzini, 2020/10/26
- [PULL 01/17] build: fix macOS --enable-modules build, Paolo Bonzini, 2020/10/26