Fix: lib: increment refcount of bt_value_null when copying it
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 15 Aug 2019 15:56:14 +0000 (11:56 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 17 Aug 2019 00:12:13 +0000 (20:12 -0400)
Value copy functions must return a new reference.  This is not done for
bt_value_null_copy, which causes refcount imbalance when a null value
gets copied.  A bug caused by this can be triggered with:

    $ git:(3e3535450850) ✗ LIBBABELTRACE2_INIT_LOG_LEVEL=W ~/build/babeltrace/src/cli/babeltrace2 -c src.ctf.fs --params='yo=null,madame=null,la=null'
    ...
    08-15 11:58:25.070  2757  2757 W LIB/VALUE bt_value_null_instance_release_func@value.c:72 Releasing the null value singleton: addr=0x7f070e1fc8e0
    08-15 11:58:25.070  2757  2757 F LIB/VALUE bt_object_put_ref@object.h:367 Babeltrace 2 library precondition not satisfied; error is:
    08-15 11:58:25.070  2757  2757 F LIB/VALUE bt_object_put_ref@object.h:367 Decrementing a reference count set to 0: addr=0x7f070e1fc8e0, ref-count=0
    08-15 11:58:25.070  2757  2757 F LIB/VALUE bt_object_put_ref@object.h:367 Aborting...

Change-Id: I338e6700201892cbe582719bf349041f316d78d8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1942
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/lib/value.c

index 77fc75b4962a235884cafa701d210e9c1a9f99f4..4009def73f9f90b13d1b7864e679ccbdf92e72b9 100644 (file)
@@ -136,6 +136,9 @@ void (* const destroy_funcs[])(struct bt_value *) = {
 static
 struct bt_value *bt_value_null_copy(const struct bt_value *null_obj)
 {
+       BT_ASSERT(null_obj == bt_value_null);
+
+       bt_object_get_no_null_check(bt_value_null);
        return (void *) bt_value_null;
 }
 
This page took 0.026569 seconds and 4 git commands to generate.