Fix: check for NULL in destroy_pretty_data
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 13 Oct 2019 03:11:57 +0000 (23:11 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 15 Oct 2019 14:31:28 +0000 (10:31 -0400)
In pretty_init, if create_pretty fails, we go to the `error` label and
call destroy_pretty_data.  However, destroy_pretty_data does not accept
a NULL pointer.

My understanding is that our "destroy" functions generally check for a
NULL pointer, and return early in that case.

Change destroy_pretty_data to do just that.

Fixes Coverity:

    *** CID 1405908:  Null pointer dereferences  (FORWARD_NULL)
    /src/plugins/text/pretty/pretty.c: 588 in pretty_init()
    582      bt_self_component_set_data(self_comp, pretty);
    583
    584      status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
    585      goto end;
    586
    587     error:
    >>>     CID 1405908:  Null pointer dereferences  (FORWARD_NULL)
    >>>     Passing null pointer "pretty" to "destroy_pretty_data", which dereferences it.
    588      destroy_pretty_data(pretty);
    589
    590     end:
    591      return status;

Reported-by: Coverity
Change-Id: I65ec6f8b2781c0a3a1166a1e68da1f47dc2da452
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2178
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/text/pretty/pretty.c

index 3f693e5a815d524f000998a304cbeb3241419789..a925b7d8fce9b9c9b936ef535b0e007d2b253882 100644 (file)
@@ -48,6 +48,10 @@ void destroy_pretty_data(struct pretty_component *pretty)
 {
        bt_self_component_port_input_message_iterator_put_ref(pretty->iterator);
 
+       if (!pretty) {
+               goto end;
+       }
+
        if (pretty->string) {
                (void) g_string_free(pretty->string, TRUE);
        }
@@ -66,6 +70,9 @@ void destroy_pretty_data(struct pretty_component *pretty)
        }
        g_free(pretty->options.output_path);
        g_free(pretty);
+
+end:
+       return;
 }
 
 static
This page took 0.025636 seconds and 4 git commands to generate.