From aa04c1b62de23763a267d97f51b1c31be170d11a Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 May 2017 18:21:48 -0400 Subject: [PATCH] ref.c: warn when the ref count goes from 0 to 18446744073709551615 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This unlikely conditin indicates a double bt_put(), or something that went really wrong, and should be reported to the user as a warning. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- lib/ref.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ref.c b/lib/ref.c index 153146af4..02d2c4e9b 100644 --- a/lib/ref.c +++ b/lib/ref.c @@ -70,6 +70,11 @@ void bt_put(void *ptr) return; } + if (BT_LOG_ON_WARN && unlikely(bt_object_get_ref_count(obj) == 0)) { + BT_LOGW("Decrementing a reference count set to 0: addr=%p", + ptr); + } + 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