diff mbox

[FFmpeg-devel] cmdutils_opencl: fix resource_leak cid 1396852

Message ID 20170112053104.18172-1-lq@chinaffmpeg.org
State Accepted
Commit aa7982577c1dee021b72f4256f48d3c030d44e73
Headers show

Commit Message

Steven Liu Jan. 12, 2017, 5:31 a.m. UTC
CID: 1396852
check the devices_list alloc status,
and release the devices_list when alloc devices error

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 cmdutils_opencl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Jan. 12, 2017, 10:51 p.m. UTC | #1
On Thu, Jan 12, 2017 at 01:31:04PM +0800, Steven Liu wrote:
> CID: 1396852
> check the devices_list alloc status,
> and release the devices_list when alloc devices error
> 
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  cmdutils_opencl.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

i think this patch is correct

thx

[...]
Steven Liu Jan. 12, 2017, 11:56 p.m. UTC | #2
2017-01-13 6:51 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Thu, Jan 12, 2017 at 01:31:04PM +0800, Steven Liu wrote:
> > CID: 1396852
> > check the devices_list alloc status,
> > and release the devices_list when alloc devices error
> >
> > Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> > ---
> >  cmdutils_opencl.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
>
> i think this patch is correct
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Breaking DRM is a little like attempting to break through a door even
> though the window is wide open and the only thing in the house is a bunch
> of things you dont want and which you would get tomorrow for free anyway
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
applied



Thanks!
diff mbox

Patch

diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c
index dd21344..655d1c9 100644
--- a/cmdutils_opencl.c
+++ b/cmdutils_opencl.c
@@ -213,22 +213,27 @@  static int compare_ocl_device_desc(const void *a, const void *b)
 
 int opt_opencl_bench(void *optctx, const char *opt, const char *arg)
 {
-    int i, j, nb_devices = 0, count = 0;
+    int i, j, nb_devices = 0, count = 0, ret = 0;
     int64_t score = 0;
     AVOpenCLDeviceList *device_list;
     AVOpenCLDeviceNode *device_node = NULL;
     OpenCLDeviceBenchmark *devices = NULL;
     cl_platform_id platform;
 
-    av_opencl_get_device_list(&device_list);
+    ret = av_opencl_get_device_list(&device_list);
+    if (ret < 0) {
+        return ret;
+    }
     for (i = 0; i < device_list->platform_num; i++)
         nb_devices += device_list->platform_node[i]->device_num;
     if (!nb_devices) {
         av_log(NULL, AV_LOG_ERROR, "No OpenCL device detected!\n");
+        av_opencl_free_device_list(&device_list);
         return AVERROR(EINVAL);
     }
     if (!(devices = av_malloc_array(nb_devices, sizeof(OpenCLDeviceBenchmark)))) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate buffer\n");
+        av_opencl_free_device_list(&device_list);
         return AVERROR(ENOMEM);
     }