CID: 1396852 check the devices_list alloc status, and release the devices_list when alloc devices error
Showing the changes to cmdutils_opencl.c (1 of 1 file). Show all
Unified · Split
| @@ -213,22 +213,27 @@ static int compare_ocl_device_desc(const void *a, const void *b) · 212 unmodified lines | |||
| 213 | 213 | ||
| 214 | int opt_opencl_bench(void *optctx, const char *opt, const char *arg) | 214 | int opt_opencl_bench(void *optctx, const char *opt, const char *arg) |
| 215 | { | 215 | { |
| 216 | int i, j, nb_devices = 0, count = 0; | 216 | int i, j, nb_devices = 0, count = 0, ret = 0; |
| 217 | int64_t score = 0; | 217 | int64_t score = 0; |
| 218 | AVOpenCLDeviceList *device_list; | 218 | AVOpenCLDeviceList *device_list; |
| 219 | AVOpenCLDeviceNode *device_node = NULL; | 219 | AVOpenCLDeviceNode *device_node = NULL; |
| 220 | OpenCLDeviceBenchmark *devices = NULL; | 220 | OpenCLDeviceBenchmark *devices = NULL; |
| 221 | cl_platform_id platform; | 221 | cl_platform_id platform; |
| 222 | 222 | ||
| 223 | av_opencl_get_device_list(&device_list); | 223 | ret = av_opencl_get_device_list(&device_list); |
| 224 | if (ret < 0) { | ||
| 225 | return ret; | ||
| 226 | } | ||
| 224 | for (i = 0; i < device_list->platform_num; i++) | 227 | for (i = 0; i < device_list->platform_num; i++) |
| 225 | nb_devices += device_list->platform_node[i]->device_num; | 228 | nb_devices += device_list->platform_node[i]->device_num; |
| 226 | if (!nb_devices) { | 229 | if (!nb_devices) { |
| 227 | av_log(NULL, AV_LOG_ERROR, "No OpenCL device detected!\n"); | 230 | av_log(NULL, AV_LOG_ERROR, "No OpenCL device detected!\n"); |
| 231 | av_opencl_free_device_list(&device_list); | ||
| 228 | return AVERROR(EINVAL); | 232 | return AVERROR(EINVAL); |
| 229 | } | 233 | } |
| 230 | if (!(devices = av_malloc_array(nb_devices, sizeof(OpenCLDeviceBenchmark)))) { | 234 | if (!(devices = av_malloc_array(nb_devices, sizeof(OpenCLDeviceBenchmark)))) { |
| 231 | av_log(NULL, AV_LOG_ERROR, "Could not allocate buffer\n"); | 235 | av_log(NULL, AV_LOG_ERROR, "Could not allocate buffer\n"); |
| 236 | av_opencl_free_device_list(&device_list); | ||
| 232 | return AVERROR(ENOMEM); | 237 | return AVERROR(ENOMEM); |
| 233 | } | 238 | } |
| 234 | 239 | ||