X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fref.c;h=ac0580137a5ad959d25fbfa29b3a3dc0a7ffae19;hb=b1d10d85a8fce649045532003b2ddae8d98e47a1;hp=0ac1014c626a47940d78d1da8a5d6f6c53f88194;hpb=83509119a945fc77faff869daaf48627e1c4b3fa;p=babeltrace.git diff --git a/lib/ref.c b/lib/ref.c index 0ac1014c..ac058013 100644 --- a/lib/ref.c +++ b/lib/ref.c @@ -27,20 +27,29 @@ #include #include -void bt_get(void *obj) +void *bt_get(void *ptr) { - if (obj) { - struct bt_object *base = obj; + struct bt_object *obj = ptr; - bt_ref_get(&base->ref_count); + if (!obj) { + goto end; } + + if (obj->parent && bt_object_get_ref_count(obj) == 0) { + bt_get(obj->parent); + } + bt_ref_get(&obj->ref_count); +end: + return obj; } -void bt_put(void *obj) +void bt_put(void *ptr) { - if (obj) { - struct bt_object *base = obj; + struct bt_object *obj = ptr; - bt_ref_put(&base->ref_count); + if (!obj) { + return; } + + bt_ref_put(&obj->ref_count); }