waylandsink: Fix memory leak of shm allocator.
authorShinya Saito <ssaito@igel.co.jp>
Wed, 1 Nov 2017 09:05:26 +0000 (18:05 +0900)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 6 Dec 2017 20:46:40 +0000 (15:46 -0500)
gst_allocator_find() needs gst_object_unref() after usage.

https://bugzilla.gnome.org/show_bug.cgi?id=790042

ext/wayland/gstwaylandsink.c
ext/wayland/wlwindow.c

index c8228cf..8d8cedb 100644 (file)
@@ -494,18 +494,20 @@ gst_wayland_create_pool (GstWaylandSink * sink, GstCaps * caps)
   GstBufferPool *pool = NULL;
   GstStructure *structure;
   gsize size = sink->video_info.size;
+  GstAllocator *alloc;
 
   pool = g_object_new (gst_wayland_pool_get_type (), NULL);
 
   structure = gst_buffer_pool_get_config (pool);
   gst_buffer_pool_config_set_params (structure, caps, size, 2, 0);
-  gst_buffer_pool_config_set_allocator (structure, gst_wl_shm_allocator_get (),
-      NULL);
 
+  alloc = gst_wl_shm_allocator_get ();
+  gst_buffer_pool_config_set_allocator (structure, alloc, NULL);
   if (!gst_buffer_pool_set_config (pool, structure)) {
     g_object_unref (pool);
     pool = NULL;
   }
+  g_object_unref (alloc);
 
   return pool;
 }
@@ -569,6 +571,7 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
   GstCaps *caps;
   GstBufferPool *pool = NULL;
   gboolean need_pool;
+  GstAllocator *alloc;
 
   gst_query_parse_allocation (query, &caps, &need_pool);
 
@@ -579,8 +582,10 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
   if (pool)
     g_object_unref (pool);
 
+  alloc = gst_wl_shm_allocator_get ();
   gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
   gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
+  g_object_unref (alloc);
 
   return TRUE;
 }
index d08ed87..c64c77a 100644 (file)
@@ -332,6 +332,7 @@ gst_wl_window_update_borders (GstWlWindow * window)
   GstBuffer *buf;
   struct wl_buffer *wlbuf;
   GstWlBuffer *gwlbuf;
+  GstAllocator *alloc;
 
   if (window->no_border_update)
     return;
@@ -354,7 +355,9 @@ gst_wl_window_update_borders (GstWlWindow * window)
   /* draw the area_subsurface */
   gst_video_info_set_format (&info, format, width, height);
 
-  buf = gst_buffer_new_allocate (gst_wl_shm_allocator_get (), info.size, NULL);
+  alloc = gst_wl_shm_allocator_get ();
+
+  buf = gst_buffer_new_allocate (alloc, info.size, NULL);
   gst_buffer_memset (buf, 0, 0, info.size);
   wlbuf =
       gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
@@ -365,6 +368,7 @@ gst_wl_window_update_borders (GstWlWindow * window)
   /* at this point, the GstWlBuffer keeps the buffer
    * alive and will free it on wl_buffer::release */
   gst_buffer_unref (buf);
+  g_object_unref (alloc);
 }
 
 void