From ef0df31c5e6f83ebcc9cc10d2d9b357ccb8ef6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bj=C3=A4reholt?= Date: Sat, 2 Nov 2019 11:49:25 +0100 Subject: [PATCH] gst-stats: Fix missing NULL checks gst-inspect-1.0 segfaults on tracing logs where it fails to find element stats. So on the pipelines where we get the following WARNING during execution will afterwards crash with a segfault as the g_ptr_array has a index for it but it is just a NULL pointer. WARN default gst-stats.c:444:do_message_stats: no element stats found for ix=X An example of an pipeline which can reproducibly create a trace log where this occurs would be this GST_DEBUG="GST_TRACER:7" GST_TRACERS="stats;rusage;latency" gst-launch-1.0 videotestsrc num-buffers=120 ! autovideosink &> trace.log gst-stats-1.0 trace.log --- tools/gst-stats.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/gst-stats.c b/tools/gst-stats.c index 2f2f61df09..acebcf5616 100644 --- a/tools/gst-stats.c +++ b/tools/gst-stats.c @@ -773,7 +773,7 @@ sort_element_stats_by_first_activity (gconstpointer es1, gconstpointer es2) static void sort_bin_stats (gpointer value, gpointer user_data) { - if (((GstElementStats *) value)->is_bin) { + if (value != NULL && ((GstElementStats *) value)->is_bin) { GSList **list = user_data; *list = @@ -785,7 +785,7 @@ sort_bin_stats (gpointer value, gpointer user_data) static void sort_element_stats (gpointer value, gpointer user_data) { - if (!(((GstElementStats *) value)->is_bin)) { + if (value != NULL && !(((GstElementStats *) value)->is_bin)) { GSList **list = user_data; *list = @@ -962,7 +962,7 @@ print_stats (void) /* attribute bin stats to parent-bins */ for (i = 0; i < num_elements; i++) { GstElementStats *stats = g_ptr_array_index (elements, i); - if (stats->is_bin) { + if (stats != NULL && stats->is_bin) { g_hash_table_insert (accum_bins, GUINT_TO_POINTER (i), stats); } }