plugins: avoid possible memory leaks

Get the pool config just before use it, to avoid a memory leak if the
allocator cannot be instantiated. Similarly, return FALSE if the configuration
cannot be set, avoid keep a not used allocator in the pool.
This commit is contained in:
Víctor Manuel Jáquez Leal 2016-06-08 18:44:34 +02:00
parent 8d7a0ae16c
commit 4c99077af4

View file

@ -495,21 +495,23 @@ set_dmabuf_allocator (GstVaapiPluginBase * plugin, GstBufferPool * pool,
GstStructure *config; GstStructure *config;
GstAllocator *allocator; GstAllocator *allocator;
GstVideoInfo vi; GstVideoInfo vi;
gboolean ret;
if (!gst_video_info_from_caps (&vi, caps)) if (!gst_video_info_from_caps (&vi, caps))
return FALSE; return FALSE;
config = gst_buffer_pool_get_config (pool);
allocator = gst_vaapi_dmabuf_allocator_new (plugin->display, &vi, allocator = gst_vaapi_dmabuf_allocator_new (plugin->display, &vi,
GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE); GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE);
if (!allocator) if (!allocator)
return FALSE; return FALSE;
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_set_allocator (config, allocator, NULL); gst_buffer_pool_config_set_allocator (config, allocator, NULL);
ret = gst_buffer_pool_set_config (pool, config); if (!gst_buffer_pool_set_config (pool, config))
return FALSE;
if (plugin->sinkpad_allocator) if (plugin->sinkpad_allocator)
gst_object_unref (plugin->sinkpad_allocator); gst_object_unref (plugin->sinkpad_allocator);
plugin->sinkpad_allocator = allocator; plugin->sinkpad_allocator = allocator;
return ret; return TRUE;
} }
static gboolean static gboolean