glimagesink: balance the creation/destruction of the overlay compositor
authorMatthew Waters <matthew@centricular.com>
Wed, 11 Nov 2015 02:37:59 +0000 (13:37 +1100)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:11 +0000 (19:32 +0000)
Fixes some leaks/possible segfault on when failing to create the compositor.

ext/gl/gstglimagesink.c

index a84ab36..f2fd3e0 100644 (file)
@@ -951,9 +951,6 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
         return GST_STATE_CHANGE_FAILURE;
       break;
     case GST_STATE_CHANGE_READY_TO_PAUSED:
-      glimage_sink->overlay_compositor =
-          gst_gl_overlay_compositor_new (glimage_sink->context);
-
       g_atomic_int_set (&glimage_sink->to_quit, 0);
       break;
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
@@ -1011,6 +1008,11 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
       break;
     }
     case GST_STATE_CHANGE_READY_TO_NULL:
+      if (glimage_sink->overlay_compositor) {
+        gst_object_unref (glimage_sink->overlay_compositor);
+        glimage_sink->overlay_compositor = NULL;
+      }
+
       if (glimage_sink->context) {
         GstGLWindow *window = gst_gl_context_get_window (glimage_sink->context);
 
@@ -1028,9 +1030,6 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
           g_signal_handler_disconnect (window, glimage_sink->mouse_sig_id);
         glimage_sink->mouse_sig_id = 0;
 
-        gst_object_unref (glimage_sink->overlay_compositor);
-        glimage_sink->overlay_compositor = NULL;
-
         gst_object_unref (window);
         gst_object_unref (glimage_sink->context);
         glimage_sink->context = NULL;
@@ -1335,6 +1334,14 @@ prepare_next_buffer (GstGLImageSink * glimage_sink)
     info = &glimage_sink->in_info;
   }
 
+  if (!glimage_sink->overlay_compositor) {
+    if (!(glimage_sink->overlay_compositor =
+            gst_gl_overlay_compositor_new (glimage_sink->context))) {
+      gst_buffer_unref (next_buffer);
+      goto fail;
+    }
+  }
+
   gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor,
       next_buffer);