From 4c99077af414064e3443b2c17a33858e5b97dee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 8 Jun 2016 18:44:34 +0200 Subject: [PATCH] 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. --- gst/vaapi/gstvaapipluginbase.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index a952057794..143c7ef7e6 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -495,21 +495,23 @@ set_dmabuf_allocator (GstVaapiPluginBase * plugin, GstBufferPool * pool, GstStructure *config; GstAllocator *allocator; GstVideoInfo vi; - gboolean ret; if (!gst_video_info_from_caps (&vi, caps)) return FALSE; - config = gst_buffer_pool_get_config (pool); allocator = gst_vaapi_dmabuf_allocator_new (plugin->display, &vi, GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE); if (!allocator) return FALSE; + + config = gst_buffer_pool_get_config (pool); 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) gst_object_unref (plugin->sinkpad_allocator); plugin->sinkpad_allocator = allocator; - return ret; + return TRUE; } static gboolean