Browse Source

cmdutils_opencl: fix resource_leak cid 1396852

CID: 1396852
check the devices_list alloc status,
and release the devices_list when alloc devices error

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
Steven Liu 8 years ago
parent
commit
aa7982577c
1 changed files with 7 additions and 2 deletions
  1. 7 2
      cmdutils_opencl.c

+ 7 - 2
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 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;
     int64_t score = 0;
     AVOpenCLDeviceList *device_list;
     AVOpenCLDeviceList *device_list;
     AVOpenCLDeviceNode *device_node = NULL;
     AVOpenCLDeviceNode *device_node = NULL;
     OpenCLDeviceBenchmark *devices = NULL;
     OpenCLDeviceBenchmark *devices = NULL;
     cl_platform_id platform;
     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++)
     for (i = 0; i < device_list->platform_num; i++)
         nb_devices += device_list->platform_node[i]->device_num;
         nb_devices += device_list->platform_node[i]->device_num;
     if (!nb_devices) {
     if (!nb_devices) {
         av_log(NULL, AV_LOG_ERROR, "No OpenCL device detected!\n");
         av_log(NULL, AV_LOG_ERROR, "No OpenCL device detected!\n");
+        av_opencl_free_device_list(&device_list);
         return AVERROR(EINVAL);
         return AVERROR(EINVAL);
     }
     }
     if (!(devices = av_malloc_array(nb_devices, sizeof(OpenCLDeviceBenchmark)))) {
     if (!(devices = av_malloc_array(nb_devices, sizeof(OpenCLDeviceBenchmark)))) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate buffer\n");
         av_log(NULL, AV_LOG_ERROR, "Could not allocate buffer\n");
+        av_opencl_free_device_list(&device_list);
         return AVERROR(ENOMEM);
         return AVERROR(ENOMEM);
     }
     }