lib: trace IR, values: reset pointers to `NULL` on destruction
[babeltrace.git] / lib / trace-ir / field-classes.c
index 6013464c19d9c45d3cececd8c5e19222f50cde14..2adf0348b9d78a26daea2c2db31e636a53ce506b 100644 (file)
@@ -137,7 +137,7 @@ bool size_is_valid_for_enumeration_field_class(struct bt_field_class *fc,
        return true;
 }
 
-int bt_private_field_class_integer_set_field_value_range(
+void bt_private_field_class_integer_set_field_value_range(
                struct bt_private_field_class *priv_fc, uint64_t size)
 {
        struct bt_field_class *fc = (void *) priv_fc;
@@ -158,7 +158,6 @@ int bt_private_field_class_integer_set_field_value_range(
                "which are outside this range: %!+F, size=%" PRIu64, fc, size);
        int_fc->range = size;
        BT_LIB_LOGV("Set integer field class's field value range: %!+F", fc);
-       return 0;
 }
 
 enum bt_field_class_integer_preferred_display_base
@@ -171,7 +170,7 @@ bt_field_class_integer_get_preferred_display_base(struct bt_field_class *fc)
        return int_fc->base;
 }
 
-int bt_private_field_class_integer_set_preferred_display_base(
+void bt_private_field_class_integer_set_preferred_display_base(
                struct bt_private_field_class *priv_fc,
                enum bt_field_class_integer_preferred_display_base base)
 {
@@ -183,7 +182,6 @@ int bt_private_field_class_integer_set_preferred_display_base(
        BT_ASSERT_PRE_FC_HOT(fc, "Field class");
        int_fc->base = base;
        BT_LIB_LOGV("Set integer field class's preferred display base: %!+F", fc);
-       return 0;
 }
 
 static
@@ -218,10 +216,12 @@ void destroy_enumeration_field_class(struct bt_object *obj)
                }
 
                g_array_free(fc->mappings, TRUE);
+               fc->mappings = NULL;
        }
 
        if (fc->label_buf) {
                g_ptr_array_free(fc->label_buf, TRUE);
+               fc->label_buf = NULL;
        }
 
        g_free(fc);
@@ -614,7 +614,7 @@ bt_bool bt_field_class_real_is_single_precision(struct bt_field_class *fc)
        return real_fc->is_single_precision;
 }
 
-int bt_private_field_class_real_set_is_single_precision(
+void bt_private_field_class_real_set_is_single_precision(
                struct bt_private_field_class *priv_fc,
                bt_bool is_single_precision)
 {
@@ -627,7 +627,6 @@ int bt_private_field_class_real_set_is_single_precision(
        real_fc->is_single_precision = (bool) is_single_precision;
        BT_LIB_LOGV("Set real field class's \"is single precision\" property: "
                "%!+F", fc);
-       return 0;
 }
 
 static
@@ -671,7 +670,7 @@ void finalize_named_field_class(struct bt_named_field_class *named_fc)
        }
 
        BT_LOGD_STR("Putting named field class's field class.");
-       bt_object_put_ref(named_fc->fc);
+       BT_OBJECT_PUT_REF_AND_RESET(named_fc->fc);
 }
 
 static
@@ -879,7 +878,9 @@ void destroy_variant_field_class(struct bt_object *obj)
        BT_LIB_LOGD("Destroying variant field class object: %!+F", fc);
        finalize_named_field_classes_container((void *) fc);
        BT_LOGD_STR("Putting selector field path.");
-       bt_object_put_ref(fc->selector_field_path);
+       BT_OBJECT_PUT_REF_AND_RESET(fc->selector_field_path);
+       BT_LOGD_STR("Putting selector field class.");
+       BT_OBJECT_PUT_REF_AND_RESET(fc->selector_fc);
        g_free(fc);
 }
 
@@ -923,7 +924,7 @@ int bt_private_field_class_variant_set_selector_field_class(
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
        BT_ASSERT_PRE_FC_IS_ENUM(selector_fc, "Selector field class");
        BT_ASSERT_PRE_FC_HOT(fc, "Variant field class");
-       var_fc->selector_fc = (void *) selector_fc;
+       var_fc->selector_fc = bt_object_get_ref(selector_fc);
        bt_field_class_freeze((void *) selector_fc);
        return 0;
 }
@@ -1011,7 +1012,7 @@ void finalize_array_field_class(struct bt_field_class_array *array_fc)
 {
        BT_ASSERT(array_fc);
        BT_LOGD_STR("Putting element field class.");
-       bt_object_put_ref(array_fc->element_fc);
+       BT_OBJECT_PUT_REF_AND_RESET(array_fc->element_fc);
 }
 
 static
@@ -1089,7 +1090,9 @@ void destroy_dynamic_array_field_class(struct bt_object *obj)
        BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc);
        finalize_array_field_class((void *) fc);
        BT_LOGD_STR("Putting length field path.");
-       bt_object_put_ref(fc->length_field_path);
+       BT_OBJECT_PUT_REF_AND_RESET(fc->length_field_path);
+       BT_LOGD_STR("Putting length field class.");
+       BT_OBJECT_PUT_REF_AND_RESET(fc->length_fc);
        g_free(fc);
 }
 
@@ -1133,7 +1136,7 @@ int bt_private_field_class_dynamic_array_set_length_field_class(
                "Field class");
        BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, "Length field class");
        BT_ASSERT_PRE_FC_HOT(fc, "Dynamic array field class");
-       array_fc->length_fc = length_fc;
+       array_fc->length_fc = bt_object_get_ref(length_fc);
        bt_field_class_freeze(length_fc);
        return 0;
 }
This page took 0.026037 seconds and 4 git commands to generate.