From b1912a652c31a5700b07500b0b1dab274d06ea17 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 May 2017 18:17:25 -0400 Subject: [PATCH] ref.c: do not change ref count when release function is not set MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is the case of the null value singleton, bt_value_null, on which you can call bt_get() and bt_put() and they should have no effect. Before this patch, we can see log messages of the ref count going from 0 to 18446744073709551615 and other weird, huge values. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- lib/ref.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ref.c b/lib/ref.c index 3a9cb61c6..153146af4 100644 --- a/lib/ref.c +++ b/lib/ref.c @@ -38,6 +38,10 @@ void *bt_get(void *ptr) goto end; } + if (unlikely(!obj->ref_count.release)) { + goto end; + } + if (unlikely(obj->parent && bt_object_get_ref_count(obj) == 0)) { BT_LOGV("Incrementing object's parent's reference count: " "addr=%p, parent-addr=%p", ptr, obj->parent); @@ -49,6 +53,7 @@ void *bt_get(void *ptr) ptr, obj->ref_count.count, obj->ref_count.count + 1); bt_ref_get(&obj->ref_count); + end: return obj; } @@ -61,6 +66,10 @@ void bt_put(void *ptr) return; } + if (unlikely(!obj->ref_count.release)) { + return; + } + BT_LOGV("Decrementing object's reference count: %lu -> %lu: " "addr=%p, cur-count=%lu, new-count=%lu", obj->ref_count.count, obj->ref_count.count - 1, -- 2.34.1