glbufferpool: fix allocator leak in some cases

Spotted by Sebastian Rasmussen.

https://bugzilla.gnome.org/show_bug.cgi?id=734523
This commit is contained in:
Tim-Philipp Müller 2014-08-10 22:58:22 +01:00 committed by Sebastian Dröge
parent 7863be66ed
commit 21e6989848

View file

@ -83,8 +83,8 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool); GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
GstGLBufferPoolPrivate *priv = glpool->priv; GstGLBufferPoolPrivate *priv = glpool->priv;
GstVideoInfo info; GstVideoInfo info;
GstCaps *caps; GstCaps *caps = NULL;
GstAllocator *allocator; GstAllocator *allocator = NULL;
GstAllocationParams alloc_params; GstAllocationParams alloc_params;
gboolean reset = TRUE; 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)) if (!gst_buffer_pool_config_get_allocator (config, &allocator, &alloc_params))
goto wrong_config; goto wrong_config;
if (priv->allocator)
gst_object_unref (priv->allocator);
if (!allocator) { if (!allocator) {
gst_gl_memory_init (); 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->params = alloc_params;
priv->im_format = GST_VIDEO_INFO_FORMAT (&info); 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); GST_BUFFER_POOL_OPTION_VIDEO_META);
#if GST_GL_HAVE_PLATFORM_EGL #if GST_GL_HAVE_PLATFORM_EGL
priv->want_eglimage = (priv->allocator g_assert (priv->allocator != NULL);
&& g_strcmp0 (priv->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0); priv->want_eglimage =
(g_strcmp0 (priv->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0);
#else #else
priv->want_eglimage = FALSE; priv->want_eglimage = FALSE;
#endif #endif
@ -368,4 +374,9 @@ gst_gl_buffer_pool_finalize (GObject * object)
gst_object_unref (pool->context); gst_object_unref (pool->context);
pool->context = NULL; pool->context = NULL;
} }
if (priv->allocator) {
gst_object_unref (priv->allocator);
priv->allocator = NULL;
}
} }