Skip to content

Commit

Permalink
qom: Assert that objects being destroyed have no parent
Browse files Browse the repository at this point in the history
QOM reference counting bugs are often hard to detect, but there's
one kind of bug that's easier: if we are freeing an object but is
still attached to a parent, it means the reference count is wrong
(because the parent always hold a reference to their children).

Add an assertion to make sure we detect those cases.

Signed-off-by: Eduardo Habkost <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
ehabkost authored and bonzini committed Jan 2, 2021
1 parent 08bdf5d commit 63f957a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions qom/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ static void object_finalize(void *data)
object_deinit(obj, ti);

g_assert(obj->ref == 0);
g_assert(obj->parent == NULL);
if (obj->free) {
obj->free(obj);
}
Expand Down

0 comments on commit 63f957a

Please sign in to comment.