gst-stats: Fix missing NULL checks
authorJohan Bjäreholt <johan@bjareho.lt>
Sat, 2 Nov 2019 10:49:25 +0000 (11:49 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 28 Feb 2020 15:14:58 +0000 (15:14 +0000)
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

index 2f2f61df099d267f2582c63a87b97a534961ffbd..acebcf561628b97eda6c8dfaa5247c56a6b63227 100644 (file)
@@ -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);
       }
     }