diff mbox

[FFmpeg-devel,1/3] cmdutils_opencl: fix resource_leak cid 1396852

Message ID 20170110114432.7519-1-lq@chinaffmpeg.org
State Superseded
Headers show

Commit Message

Steven Liu Jan. 10, 2017, 11:44 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 | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Jan. 11, 2017, 7:29 p.m. UTC | #1
On Tue, Jan 10, 2017 at 07:44:32PM +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 | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c
> index dd21344..5bbc8dc 100644
> --- a/cmdutils_opencl.c
> +++ b/cmdutils_opencl.c
> @@ -220,15 +220,20 @@ int opt_opencl_bench(void *optctx, const char *opt, const char *arg)
>      OpenCLDeviceBenchmark *devices = NULL;
>      cl_platform_id platform;
>  
> -    av_opencl_get_device_list(&device_list);
> +    if (av_opencl_get_device_list(&device_list) < 0) {
> +        return AVERROR(ENOMEM);
> +    }

The error code from av_opencl_get_device_list() should be forwarded

thx

[...]
Wei Gao Feb. 8, 2017, 3:38 a.m. UTC | #2
2017-01-12 3:29 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Tue, Jan 10, 2017 at 07:44:32PM +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 | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c
> > index dd21344..5bbc8dc 100644
> > --- a/cmdutils_opencl.c
> > +++ b/cmdutils_opencl.c
> > @@ -220,15 +220,20 @@ int opt_opencl_bench(void *optctx, const char
> *opt, const char *arg)
> >      OpenCLDeviceBenchmark *devices = NULL;
> >      cl_platform_id platform;
> >
> > -    av_opencl_get_device_list(&device_list);
> > +    if (av_opencl_get_device_list(&device_list) < 0) {
> > +        return AVERROR(ENOMEM);
> > +    }
>
> The error code from av_opencl_get_device_list() should be forwarded
>
> thx
>
Hi

Looks good to me

Thanks

>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> The educated differ from the uneducated as much as the living from the
> dead. -- Aristotle
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
diff mbox

Patch

diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c
index dd21344..5bbc8dc 100644
--- a/cmdutils_opencl.c
+++ b/cmdutils_opencl.c
@@ -220,15 +220,20 @@  int opt_opencl_bench(void *optctx, const char *opt, const char *arg)
     OpenCLDeviceBenchmark *devices = NULL;
     cl_platform_id platform;
 
-    av_opencl_get_device_list(&device_list);
+    if (av_opencl_get_device_list(&device_list) < 0) {
+        return AVERROR(ENOMEM);
+    }
+
     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);
     }