From 8a6023a38ad4e9305fe725f7872b828e6a311d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alicia=20Boya=20Garc=C3=ADa?= Date: Thu, 2 Jan 2020 22:24:36 +0100 Subject: [PATCH] qtdemux: Use safer clearing functions in dispose() In theory, `dispose()` functions should be idempotent and should be prepared not to crash or cause a double-free if an unref done from inside caused a recursive call to `dispose()` of the same object. https://developer.gnome.org/gobject/stable/howto-gobject-destruction.html This patch modifies the `dispose()` method to honor these constraints. Since the double `dispose()` call won't actually occur in qtdemux (there is no cycle detection mechanism that could invoke it to work that way), this is more of a code cleanup than a user-facing problem fix. Part-of: --- .../gst-plugins-good/gst/isomp4/qtdemux.c | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c index 23eafe0de6..f5894303a3 100644 --- a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c +++ b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c @@ -469,6 +469,11 @@ gst_qtdemux_finalize (GObject * object) GstQTDemux *qtdemux = GST_QTDEMUX (object); g_free (qtdemux->redirect_location); + g_free (qtdemux->cenc_aux_info_sizes); + g_mutex_clear (&qtdemux->expose_lock); + + g_ptr_array_free (qtdemux->active_streams, TRUE); + g_ptr_array_free (qtdemux->old_streams, TRUE); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -478,22 +483,13 @@ gst_qtdemux_dispose (GObject * object) { GstQTDemux *qtdemux = GST_QTDEMUX (object); - if (qtdemux->adapter) { - g_object_unref (G_OBJECT (qtdemux->adapter)); - qtdemux->adapter = NULL; - } - gst_tag_list_unref (qtdemux->tag_list); - gst_flow_combiner_free (qtdemux->flowcombiner); + g_clear_object (&qtdemux->adapter); + gst_clear_tag_list (&qtdemux->tag_list); + g_clear_pointer (&qtdemux->flowcombiner, gst_flow_combiner_unref); + g_queue_clear_full (&qtdemux->protection_event_queue, (GDestroyNotify) gst_event_unref); - g_free (qtdemux->cenc_aux_info_sizes); - qtdemux->cenc_aux_info_sizes = NULL; - g_mutex_clear (&qtdemux->expose_lock); - - g_ptr_array_free (qtdemux->active_streams, TRUE); - g_ptr_array_free (qtdemux->old_streams, TRUE); - G_OBJECT_CLASS (parent_class)->dispose (object); }