From 0720d20cf39c9c22db9dd7c698ee50875795c2e0 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sun, 22 Jun 2025 21:47:28 +0200 Subject: [PATCH] fix memory leaks --- src/backend.c | 5 +++++ src/ext_sysfs_cpu.c | 49 +++++++++++++++++++++++++++------------------ src/user_options.c | 5 +++++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/backend.c b/src/backend.c index 02cdd73b8..32f4ec49b 100644 --- a/src/backend.c +++ b/src/backend.c @@ -8636,6 +8636,11 @@ void backend_ctx_devices_destroy (hashcat_ctx_t *hashcat_ctx) hcfree (device_param->opencl_device_c_version); hcfree (device_param->opencl_device_vendor); } + + if (device_param->is_hip == true) + { + hcfree (device_param->gcnArchName); + } } backend_ctx->backend_devices_cnt = 0; diff --git a/src/ext_sysfs_cpu.c b/src/ext_sysfs_cpu.c index 54683d741..5b89023d5 100644 --- a/src/ext_sysfs_cpu.c +++ b/src/ext_sysfs_cpu.c @@ -44,12 +44,9 @@ void sysfs_cpu_close (void *hashcat_ctx) char *hm_SYSFS_CPU_get_syspath_hwmon (void) { - char *found[4]; + char *found = NULL; - found[0] = NULL; - found[1] = NULL; - found[2] = NULL; - found[3] = NULL; + int best = 4; // 16 ok? @@ -61,31 +58,43 @@ char *hm_SYSFS_CPU_get_syspath_hwmon (void) HCFILE fp; - if (hc_fopen_raw (&fp, path, "rb") == false) continue; + if (hc_fopen_raw (&fp, path, "rb") == false) + { + hcfree (path); + + continue; + } char buf[64] = { 0 }; const size_t line_len = fgetl (&fp, buf, sizeof (buf)); - if (line_len) - { - if (strcmp (buf, SENSOR_CORETEMP) == 0) hc_asprintf (&found[0], "%s/hwmon%d", SYSFS_HWMON, i); - if (strcmp (buf, SENSOR_K10TEMP) == 0) hc_asprintf (&found[1], "%s/hwmon%d", SYSFS_HWMON, i); - if (strcmp (buf, SENSOR_K8TEMP) == 0) hc_asprintf (&found[2], "%s/hwmon%d", SYSFS_HWMON, i); - if (strcmp (buf, SENSOR_ACPITZ) == 0) hc_asprintf (&found[3], "%s/hwmon%d", SYSFS_HWMON, i); - } - hc_fclose (&fp); hcfree (path); + + if (line_len == 0) continue; + + int tmp_best = -1; + + if (strcmp (buf, SENSOR_CORETEMP) == 0) tmp_best = 0; + if (strcmp (buf, SENSOR_K10TEMP) == 0) tmp_best = 1; + if (strcmp (buf, SENSOR_K8TEMP) == 0) tmp_best = 2; + if (strcmp (buf, SENSOR_ACPITZ) == 0) tmp_best = 3; + + if (tmp_best >= 0 && tmp_best < best) + { + hcfree (found); + + best = tmp_best; + + hc_asprintf (&found, "%s/hwmon%d", SYSFS_HWMON, i); + + if (best == 0) break; + } } - if (found[0]) return found[0]; - if (found[1]) return found[1]; - if (found[2]) return found[2]; - if (found[3]) return found[3]; - - return NULL; + return found; } int hm_SYSFS_CPU_get_temperature_current (void *hashcat_ctx, int *val) diff --git a/src/user_options.c b/src/user_options.c index 23e195ee6..c2a1bd634 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -324,6 +324,11 @@ void user_options_destroy (hashcat_ctx_t *hashcat_ctx) hcfree (user_options->rp_files); + if (user_options->backend_info > 0) + { + hcfree (user_options->opencl_device_types); + } + //do not reset this, it might be used from main.c //memset (user_options, 0, sizeof (user_options_t)); }