From 15cd3d3d5c44d43437187e2f3651b3c5b9da8f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 10 Aug 2014 22:58:22 +0100 Subject: [PATCH] glbufferpool: fix allocator leak in some cases Spotted by Sebastian Rasmussen. https://bugzilla.gnome.org/show_bug.cgi?id=734523 --- gst-libs/gst/gl/gstglbufferpool.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gst-libs/gst/gl/gstglbufferpool.c b/gst-libs/gst/gl/gstglbufferpool.c index e716527eb1..88604b73cc 100644 --- a/gst-libs/gst/gl/gstglbufferpool.c +++ b/gst-libs/gst/gl/gstglbufferpool.c @@ -83,8 +83,8 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool); GstGLBufferPoolPrivate *priv = glpool->priv; GstVideoInfo info; - GstCaps *caps; - GstAllocator *allocator; + GstCaps *caps = NULL; + GstAllocator *allocator = NULL; GstAllocationParams alloc_params; gboolean reset = TRUE; @@ -104,11 +104,16 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) if (!gst_buffer_pool_config_get_allocator (config, &allocator, &alloc_params)) goto wrong_config; + if (priv->allocator) + gst_object_unref (priv->allocator); + if (!allocator) { gst_gl_memory_init (); - allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR); + priv->allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR); + } else { + priv->allocator = gst_object_ref (allocator); } - priv->allocator = allocator; + priv->params = alloc_params; priv->im_format = GST_VIDEO_INFO_FORMAT (&info); @@ -125,8 +130,9 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) GST_BUFFER_POOL_OPTION_VIDEO_META); #if GST_GL_HAVE_PLATFORM_EGL - priv->want_eglimage = (priv->allocator - && g_strcmp0 (priv->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0); + g_assert (priv->allocator != NULL); + priv->want_eglimage = + (g_strcmp0 (priv->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0); #else priv->want_eglimage = FALSE; #endif @@ -368,4 +374,9 @@ gst_gl_buffer_pool_finalize (GObject * object) gst_object_unref (pool->context); pool->context = NULL; } + + if (priv->allocator) { + gst_object_unref (priv->allocator); + priv->allocator = NULL; + } }