From 6ef802a14836c7f4a01d84f6161859b1262da671 Mon Sep 17 00:00:00 2001 From: philsmd Date: Tue, 14 Feb 2017 11:52:53 +0100 Subject: [PATCH] OpenCL platforms/devices: Fixed several memory leaks when a platform/device could not be used/initialized --- docs/changes.txt | 1 + src/opencl.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3d8e12ee8..748b94d61 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -62,6 +62,7 @@ - Files: Do several file and folder checks on startup rather than when they are actually used to avoid related error after eventual intense operations - Helper: Added functions to check existence, type, read- and write-permissions and rewrite sources to use them instead of stat() - Hardware Monitor: Fixed several memory leaks when no hardware monitor sensor is found +- OpenCL Device Management: Fixed several memory leaks when initialization of a device/platform failed - OpenCL Header: Updated CL_* errorcode to OpenCL 1.2 standard - OpenCL Runtime: Updated AMDGPU-Pro driver version check, do warn if version 16.60 is detected which is known to be broken - OpenCL Kernel: Renumbered hash-mode 7600 to 4521 diff --git a/src/opencl.c b/src/opencl.c index a53276b60..ac5e2f38e 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -2209,7 +2209,22 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) int CL_rc = hc_clGetPlatformIDs (hashcat_ctx, CL_PLATFORMS_MAX, platforms, &platforms_cnt); - if (CL_rc == -1) return -1; + #define FREE_OPENCL_CTX_ON_ERROR \ + { \ + hcfree (platforms_vendor); \ + hcfree (platforms_name); \ + hcfree (platforms_version); \ + hcfree (platforms_skipped); \ + hcfree (platforms); \ + hcfree (platform_devices); \ + } + + if (CL_rc == -1) + { + FREE_OPENCL_CTX_ON_ERROR; + + return -1; + } if (platforms_cnt == 0) { @@ -2233,6 +2248,8 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) event_log_error (hashcat_ctx, "* NVidia users require \"NVIDIA Driver\" (367.x or later)"); + FREE_OPENCL_CTX_ON_ERROR; + return -1; } @@ -2244,6 +2261,8 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%u)", platforms_cnt); + FREE_OPENCL_CTX_ON_ERROR; + return -1; } } @@ -2275,7 +2294,12 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - if (CL_rc == -1) return -1; + if (CL_rc == -1) + { + FREE_OPENCL_CTX_ON_ERROR; + + return -1; + } device_types_all |= device_type; }