lib: add null checks before "casting" to "base class"
[babeltrace.git] / src / lib / error.c
index 9144bd96ddc528c9f52e47afe88d0c195bd678ed..bd8259ab71057103385d75b711ffd59a5508007a 100644 (file)
@@ -300,8 +300,10 @@ struct bt_error_cause_component_actor *create_error_cause_component_actor(
        goto end;
 
 error:
-       destroy_error_cause(&cause->base);
-       cause = NULL;
+       if (cause) {
+               destroy_error_cause(&cause->base);
+               cause = NULL;
+       }
 
 end:
        return cause;
@@ -341,8 +343,10 @@ create_error_cause_component_class_actor(struct bt_component_class *comp_cls,
        goto end;
 
 error:
-       destroy_error_cause(&cause->base);
-       cause = NULL;
+       if (cause) {
+               destroy_error_cause(&cause->base);
+               cause = NULL;
+       }
 
 end:
        return cause;
@@ -407,8 +411,10 @@ create_error_cause_message_iterator_actor(struct bt_message_iterator *iter,
        goto end;
 
 error:
-       destroy_error_cause(&cause->base);
-       cause = NULL;
+       if (cause) {
+               destroy_error_cause(&cause->base);
+               cause = NULL;
+       }
 
 end:
        return cause;
@@ -523,7 +529,10 @@ int bt_error_append_cause_from_component(
        cause = NULL;
 
 end:
-       destroy_error_cause(&cause->base);
+       if (cause) {
+               destroy_error_cause(&cause->base);
+       }
+
        return status;
 }
 
@@ -557,7 +566,10 @@ int bt_error_append_cause_from_component_class(
        cause = NULL;
 
 end:
-       destroy_error_cause(&cause->base);
+       if (cause) {
+               destroy_error_cause(&cause->base);
+       }
+
        return status;
 }
 
@@ -590,7 +602,10 @@ int bt_error_append_cause_from_message_iterator(
        cause = NULL;
 
 end:
-       destroy_error_cause(&cause->base);
+       if (cause) {
+               destroy_error_cause(&cause->base);
+       }
+
        return status;
 }
 
This page took 0.023708 seconds and 4 git commands to generate.