From 27a1afa74b56f211aa0a44acf268501b73c15aa9 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 12 Oct 2019 23:11:57 -0400 Subject: [PATCH] Fix: check for NULL in destroy_pretty_data 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2178 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- src/plugins/text/pretty/pretty.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/text/pretty/pretty.c b/src/plugins/text/pretty/pretty.c index 3f693e5a..a925b7d8 100644 --- a/src/plugins/text/pretty/pretty.c +++ b/src/plugins/text/pretty/pretty.c @@ -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 -- 2.34.1