qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qom: Make object_unref() free the object's memory when refcount goes to 0.
@ 2012-02-22 18:00 alexander_barabash
  2012-02-22 19:12 ` Anthony Liguori
  0 siblings, 1 reply; 5+ messages in thread
From: alexander_barabash @ 2012-02-22 18:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, Alexander Barabash

From: Alexander Barabash <alexander_barabash@mentor.com>

In the existing implementation, object_delete()
calls object_unref(), then frees the object's storage.
Running object_delete() on an object with reference count
different from 1 causes program failure.

In the existing implementation, object_unref()
finalizes the object when its reference count becomes 0.

In the new implementation, object_unref()
finalizes and frees the object's storage when the reference count becomes 0.

In the new implementation, object_delete()
just calls object_unref().
Running object_delete() on an object with reference count
different from 1 still causes program failure.

Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com>
---
 qom/object.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index e6591e1..8d36a9c 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -373,9 +373,8 @@ Object *object_new(const char *typename)
 
 void object_delete(Object *obj)
 {
+    g_assert(obj->ref == 1);
     object_unref(obj);
-    g_assert(obj->ref == 0);
-    g_free(obj);
 }
 
 static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
@@ -585,6 +584,7 @@ void object_unref(Object *obj)
     /* parent always holds a reference to its children */
     if (obj->ref == 0) {
         object_finalize(obj);
+        g_free(obj);
     }
 }
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-26  9:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-22 18:00 [Qemu-devel] [PATCH] qom: Make object_unref() free the object's memory when refcount goes to 0 alexander_barabash
2012-02-22 19:12 ` Anthony Liguori
2012-02-23 16:21   ` Alexander Barabash
2012-02-24 15:11     ` Anthony Liguori
2012-02-26  9:54       ` Alexander Barabash

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).