From: Jérémie Galarneau Date: Fri, 10 Mar 2017 19:11:29 +0000 (-0500) Subject: Fix: release the reference held by a child to its former parent X-Git-Tag: v2.0.0-pre1~447 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=5ed184457e505c1cf104918ebec0fc2ce528d89d Fix: release the reference held by a child to its former parent The bt_object class' bt_object_set_parent() increments the reference count of the parent since the child now holds a reference to it. This assumes that a child is externally visible when this call is made (as is always the case currently). The parent of a child can be changed in the future. In this case, we want to ensure the reference it held to its former parent is released. Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/object-internal.h b/include/babeltrace/object-internal.h index 4bf4def6..5c3ca6d9 100644 --- a/include/babeltrace/object-internal.h +++ b/include/babeltrace/object-internal.h @@ -96,6 +96,7 @@ void bt_object_set_parent(void *child_ptr, void *parent) * to the parent will be released once the object's reference count * falls to zero. */ + BT_PUT(child->parent); child->parent = bt_get(parent); }