Fix: lib: add NULL check for destroy_listeners in destroy_component_class
[babeltrace.git] / src / lib / graph / component-class.c
index 7f31aa3022850ebef7e2aba6ba9a344003c4d6e5..538cd77be1daff6a254ee80bffd03cf3ac087c6d 100644 (file)
@@ -20,7 +20,8 @@
 #include "lib/graph/message-iterator-class.h"
 
 #define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc)                            \
-       BT_ASSERT_PRE_DEV_HOT(((const struct bt_component_class *) (_cc)), \
+       BT_ASSERT_PRE_DEV_HOT("component-class",                        \
+               ((const struct bt_component_class *) (_cc)), \
                "Component class", ": %!+C", (_cc))
 
 static
@@ -35,15 +36,17 @@ void destroy_component_class(struct bt_object *obj)
        BT_LIB_LOGI("Destroying component class: %!+C", class);
 
        /* Call destroy listeners in reverse registration order */
-       for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
-               struct bt_component_class_destroy_listener *listener =
-                       &g_array_index(class->destroy_listeners,
-                               struct bt_component_class_destroy_listener,
-                               i);
-
-               BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
-                       listener->func, listener->data);
-               listener->func(class, listener->data);
+       if (class->destroy_listeners) {
+               for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
+                       struct bt_component_class_destroy_listener *listener =
+                               &g_array_index(class->destroy_listeners,
+                                       struct bt_component_class_destroy_listener,
+                                       i);
+
+                       BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
+                               listener->func, listener->data);
+                       listener->func(class, listener->data);
+               }
        }
 
        if (class->name) {
@@ -239,7 +242,7 @@ struct bt_component_class_sink *bt_component_class_sink_create(
 
        BT_ASSERT_PRE_NO_ERROR();
        BT_ASSERT_PRE_NAME_NON_NULL(name);
-       BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
+       BT_ASSERT_PRE_NON_NULL("consume-method", method, "Consume next method");
        BT_LOGI("Creating sink component class: "
                "name=\"%s\", consume-method-addr=%p",
                name, method);
@@ -539,7 +542,7 @@ bt_component_class_set_description(
                "addr=%p, name=\"%s\", type=%s",
                comp_cls,
                bt_component_class_get_name(comp_cls),
-               bt_component_class_type_string(comp_cls->type));
+               bt_common_component_class_type_string(comp_cls->type));
        return BT_FUNC_STATUS_OK;
 }
 
@@ -549,7 +552,7 @@ enum bt_component_class_set_help_status bt_component_class_set_help(
 {
        BT_ASSERT_PRE_NO_ERROR();
        BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
-       BT_ASSERT_PRE_NON_NULL(help, "Help");
+       BT_ASSERT_PRE_NON_NULL("help-text", help, "Help text");
        BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
        g_string_assign(comp_cls->help, help);
        BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
This page took 0.023754 seconds and 4 git commands to generate.