From 718c4b7ca1d368514d0e0de5bf71b30cdf05473b Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Mon, 19 Aug 2019 23:33:12 -0400 Subject: [PATCH] Fix: sink.utils.counter: possible NULL pointer dereference MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If the null check at line 148 is true, the `counter` pointer might be used will be used while being NULL by the `destroy_private_counter_data()` function. scan-build report: Access to field 'msg_iter' results in a dereference of a null pointer (loaded from variable 'counter') Reported-by: scan-build - Logic error Dereference of null pointer Signed-off-by: Francis Deslauriers Change-Id: I50bb981433ef3f5083613b36bbef54743cddb4c2 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1970 Tested-by: jenkins Reviewed-by: Jérémie Galarneau Reviewed-by: Simon Marchi --- src/plugins/utils/counter/counter.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/utils/counter/counter.c b/src/plugins/utils/counter/counter.c index 6284438f..2ad60167 100644 --- a/src/plugins/utils/counter/counter.c +++ b/src/plugins/utils/counter/counter.c @@ -114,8 +114,11 @@ void try_print_last(struct counter *counter) void destroy_private_counter_data(struct counter *counter) { - bt_self_component_port_input_message_iterator_put_ref(counter->msg_iter); - g_free(counter); + if (counter) { + bt_self_component_port_input_message_iterator_put_ref( + counter->msg_iter); + g_free(counter); + } } BT_HIDDEN -- 2.34.1