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
This commit is contained in:
Johan Bjäreholt 2019-11-02 11:49:25 +01:00 committed by Tim-Philipp Müller
parent 19f414c0d1
commit ef0df31c5e

View file

@ -773,7 +773,7 @@ sort_element_stats_by_first_activity (gconstpointer es1, gconstpointer es2)
static void static void
sort_bin_stats (gpointer value, gpointer user_data) sort_bin_stats (gpointer value, gpointer user_data)
{ {
if (((GstElementStats *) value)->is_bin) { if (value != NULL && ((GstElementStats *) value)->is_bin) {
GSList **list = user_data; GSList **list = user_data;
*list = *list =
@ -785,7 +785,7 @@ sort_bin_stats (gpointer value, gpointer user_data)
static void static void
sort_element_stats (gpointer value, gpointer user_data) sort_element_stats (gpointer value, gpointer user_data)
{ {
if (!(((GstElementStats *) value)->is_bin)) { if (value != NULL && !(((GstElementStats *) value)->is_bin)) {
GSList **list = user_data; GSList **list = user_data;
*list = *list =
@ -962,7 +962,7 @@ print_stats (void)
/* attribute bin stats to parent-bins */ /* attribute bin stats to parent-bins */
for (i = 0; i < num_elements; i++) { for (i = 0; i < num_elements; i++) {
GstElementStats *stats = g_ptr_array_index (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); g_hash_table_insert (accum_bins, GUINT_TO_POINTER (i), stats);
} }
} }