X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fref.c;h=ac0580137a5ad959d25fbfa29b3a3dc0a7ffae19;hb=192803e1a1967fa87ac37b3e962b439101541962;hp=e642e266de87543c24f9f3819e6c8b7a577c1b46;hpb=b82cd9f0ac23ce23386d4cf3d6b46aaf09293770;p=babeltrace.git diff --git a/lib/ref.c b/lib/ref.c index e642e266..ac058013 100644 --- a/lib/ref.c +++ b/lib/ref.c @@ -27,21 +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); }