[v1,1/2] qom/object.c: Reset interface list on inheritance

Message ID 145f4add-f88a-40e1-817d-dbe2e0cdd038@DB3EHSMHS014.ehs.local
State New
Headers show

Commit Message

Peter Crosthwaite Feb. 11, 2013, 7:29 a.m.
The QOM framework will attempt the recreate a classes interface list from
scratch for each class. This means that a child class should zero out the
list of interfaces when cloned from the parent class.

Currently the list is memcpy()d from the parent to the child. As the interface
list is just a pointer to a list, this means the parent and child will share
the same list of interfaces. When the child inits, it will append its own
interfaces to the parents list. This is incorrect as the parent should not pick
up its childs interfaces.

This actually causes an infinite loop at class init time, as the child will
iterate through the parent interface list adding each itf to its own list(in
type_initialize()). As the list is (erroneously) shared, the new interface
instances for the child are appended to the parent, and the iterator never hits
the tail and loops forever.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

 qom/object.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)


Anthony Liguori Feb. 22, 2013, 5:01 p.m. | #1
Applied.  Thanks.


Anthony Liguori


diff --git a/qom/object.c b/qom/object.c
index 563e45b..4b72a64 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -245,6 +245,7 @@  static void type_initialize(TypeImpl *ti)
         g_assert(parent->class_size <= ti->class_size);
         memcpy(ti->class, parent->class, parent->class_size);
+        ti->class->interfaces = NULL;
         for (e = parent->class->interfaces; e; e = e->next) {
             ObjectClass *iface = e->data;