diff options
author | maxd <[email protected]> | 2017-03-10 11:03:57 +0100 |
---|---|---|
committer | Bradley Sepos <[email protected]> | 2017-03-10 11:30:56 -0500 |
commit | 69231c990576f34c14054a6f81b09b5a445d1b47 (patch) | |
tree | 4b79eedccdd43aefc7e1d045c5c1be70a27530bd /libhb | |
parent | c6633353555fbc58a13ad90f8dfc171430455eae (diff) |
opencl: fixing more resource leaks
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/openclwrapper.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/libhb/openclwrapper.c b/libhb/openclwrapper.c index 52b052519..8ca2f9f51 100644 --- a/libhb/openclwrapper.c +++ b/libhb/openclwrapper.c @@ -248,13 +248,14 @@ int hb_write_binary_to_file( const char* fileName, const char* birary, size_t nu */ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_name ) { - int i = 0; - cl_int status; - cl_uint numDevices; - size_t *binarySizes; - cl_device_id *devices; - char **binaries; - char *str = NULL; + int i = 0; + cl_int status = CL_SUCCESS; + cl_uint numDevices = 0; + size_t *binarySizes = NULL; + cl_device_id *devices = NULL; + char **binaries = NULL; + char *str = NULL; + int ret_value = 1; if (hb_ocl == NULL) { @@ -274,7 +275,8 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if( devices == NULL ) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: no device found"); - return 0; + ret_value = 0; + goto to_exit; } /* grab the handles to all of the devices in the program. */ @@ -284,7 +286,8 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if( status != CL_SUCCESS ) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: clGetProgramInfo for CL_PROGRAM_DEVICES failed"); - return 0; + ret_value = 0; + goto to_exit; } /* figure out the sizes of each of the binaries. */ @@ -296,7 +299,8 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if( status != CL_SUCCESS ) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: clGetProgramInfo for CL_PROGRAM_BINARY_SIZES failed"); - return 0; + ret_value = 0; + goto to_exit; } /* copy over all of the generated binaries. */ @@ -304,7 +308,8 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if( binaries == NULL ) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: malloc for binaries failed"); - return 0; + ret_value = 0; + goto to_exit; } for( i = 0; i < numDevices; i++ ) @@ -315,7 +320,8 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if( binaries[i] == NULL ) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: malloc for binaries[%d] failed", i); - return 0; + ret_value = 0; + goto to_exit; } } else @@ -330,7 +336,8 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if( status != CL_SUCCESS ) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: clGetProgramInfo for CL_PROGRAM_BINARIES failed"); - return 0; + ret_value = 0; + goto to_exit; } /* dump out each binary into its own separate file. */ @@ -353,11 +360,13 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ if (!hb_write_binary_to_file(fileName, binaries[i], binarySizes[i])) { hb_log("OpenCL: hb_generat_bin_from_kernel_source: unable to write kernel, writing to temporary directory instead."); - return 0; + ret_value = 0; + goto to_exit; } } } +to_exit: // Release all resouces and memory for( i = 0; i < numDevices; i++ ) { @@ -385,7 +394,7 @@ int hb_generat_bin_from_kernel_source( cl_program program, const char * cl_file_ free( devices ); devices = NULL; } - return 1; + return ret_value; } |