1
mirror of https://github.com/hashcat/hashcat synced 2024-12-01 20:18:12 +01:00

Hardware Monitor: Fixed several memory leaks when no AMDGPU-Pro hardware monitor sensor is found

This commit is contained in:
jsteube 2017-02-14 12:30:15 +01:00
parent 663235a02a
commit ce5117631e

View File

@ -81,15 +81,20 @@ static char *hm_SYSFS_get_syspath_hwmon (hashcat_ctx_t *hashcat_ctx, const int d
{ {
event_log_error (hashcat_ctx, "first_file_in_directory() failed"); event_log_error (hashcat_ctx, "first_file_in_directory() failed");
hcfree (syspath);
hcfree (hwmon);
hcfree (hwmonN);
return NULL; return NULL;
} }
snprintf (hwmon, HCBUFSIZ_TINY - 1, "%s/hwmon/%s", syspath, hwmonN); snprintf (hwmon, HCBUFSIZ_TINY - 1, "%s/hwmon/%s", syspath, hwmonN);
hcfree (hwmonN);
hcfree (syspath); hcfree (syspath);
hcfree (hwmonN);
return hwmon; return hwmon;
} }
@ -113,6 +118,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
{ {
event_log_error (hashcat_ctx, "%s: %s", path_cur, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path_cur, strerror (errno));
hcfree (path_cur);
hcfree (path_max);
return -1; return -1;
} }
@ -124,6 +132,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
event_log_error (hashcat_ctx, "%s: unexpected data", path_cur); event_log_error (hashcat_ctx, "%s: unexpected data", path_cur);
hcfree (path_cur);
hcfree (path_max);
return -1; return -1;
} }
@ -135,6 +146,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
{ {
event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno));
hcfree (path_cur);
hcfree (path_max);
return -1; return -1;
} }
@ -146,6 +160,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
event_log_error (hashcat_ctx, "%s: unexpected data", path_max); event_log_error (hashcat_ctx, "%s: unexpected data", path_max);
hcfree (path_cur);
hcfree (path_max);
return -1; return -1;
} }
@ -155,6 +172,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
{ {
event_log_error (hashcat_ctx, "%s: pwm1_max can not be 0", path_max); event_log_error (hashcat_ctx, "%s: pwm1_max can not be 0", path_max);
hcfree (path_cur);
hcfree (path_max);
return -1; return -1;
} }
@ -188,6 +208,8 @@ static int hm_SYSFS_set_fan_control (hashcat_ctx_t *hashcat_ctx, const int devic
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
return -1; return -1;
} }
@ -220,6 +242,9 @@ static int hm_SYSFS_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int
{ {
event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno));
hcfree (path);
hcfree (path_max);
return -1; return -1;
} }
@ -231,6 +256,9 @@ static int hm_SYSFS_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int
event_log_error (hashcat_ctx, "%s: unexpected data", path_max); event_log_error (hashcat_ctx, "%s: unexpected data", path_max);
hcfree (path);
hcfree (path_max);
return -1; return -1;
} }
@ -240,6 +268,9 @@ static int hm_SYSFS_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int
{ {
event_log_error (hashcat_ctx, "%s: pwm1_max can not be 0", path_max); event_log_error (hashcat_ctx, "%s: pwm1_max can not be 0", path_max);
hcfree (path);
hcfree (path_max);
return -1; return -1;
} }
@ -251,6 +282,9 @@ static int hm_SYSFS_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
hcfree (path_max);
return -1; return -1;
} }
@ -258,8 +292,8 @@ static int hm_SYSFS_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int
fclose (fd); fclose (fd);
hcfree (path_max);
hcfree (path); hcfree (path);
hcfree (path_max);
return 0; return 0;
} }
@ -282,6 +316,8 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
return -1; return -1;
} }
@ -293,6 +329,8 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i
event_log_error (hashcat_ctx, "%s: unexpected data", path); event_log_error (hashcat_ctx, "%s: unexpected data", path);
hcfree (path);
return -1; return -1;
} }
@ -323,6 +361,8 @@ static int hm_SYSFS_get_pp_dpm_sclk (hashcat_ctx_t *hashcat_ctx, const int devic
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
return -1; return -1;
} }
@ -376,6 +416,8 @@ static int hm_SYSFS_get_pp_dpm_mclk (hashcat_ctx_t *hashcat_ctx, const int devic
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
return -1; return -1;
} }
@ -429,6 +471,8 @@ static int hm_SYSFS_get_pp_dpm_pcie (hashcat_ctx_t *hashcat_ctx, const int devic
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
return -1; return -1;
} }
@ -483,6 +527,8 @@ static int hm_SYSFS_set_power_dpm_force_performance_level (hashcat_ctx_t *hashca
{ {
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
hcfree (path);
return -1; return -1;
} }
@ -3280,6 +3326,15 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
hm_attrs_t *hm_adapters_xnvctrl = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t)); hm_attrs_t *hm_adapters_xnvctrl = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t));
hm_attrs_t *hm_adapters_sysfs = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t)); hm_attrs_t *hm_adapters_sysfs = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t));
#define FREE_ADAPTERS \
{ \
hcfree (hm_adapters_adl); \
hcfree (hm_adapters_nvapi); \
hcfree (hm_adapters_nvml); \
hcfree (hm_adapters_xnvctrl); \
hcfree (hm_adapters_sysfs); \
}
if (opencl_ctx->need_nvml == true) if (opencl_ctx->need_nvml == true)
{ {
hwmon_ctx->hm_nvml = (NVML_PTR *) hcmalloc (sizeof (NVML_PTR)); hwmon_ctx->hm_nvml = (NVML_PTR *) hcmalloc (sizeof (NVML_PTR));
@ -3510,7 +3565,12 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
int tmp_in; int tmp_in;
if (get_adapters_num_adl (hashcat_ctx, &tmp_in) == -1) return -1; if (get_adapters_num_adl (hashcat_ctx, &tmp_in) == -1)
{
FREE_ADAPTERS;
return -1;
}
// adapter info // adapter info
@ -3518,7 +3578,12 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
const int rc_adapter_info_adl = hm_ADL_Adapter_AdapterInfo_Get (hashcat_ctx, lpAdapterInfo, tmp_in * sizeof (AdapterInfo)); const int rc_adapter_info_adl = hm_ADL_Adapter_AdapterInfo_Get (hashcat_ctx, lpAdapterInfo, tmp_in * sizeof (AdapterInfo));
if (rc_adapter_info_adl == -1) return -1; if (rc_adapter_info_adl == -1)
{
FREE_ADAPTERS;
return -1;
}
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
{ {
@ -3596,11 +3661,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (hwmon_ctx->hm_adl == NULL && hwmon_ctx->hm_nvml == NULL && hwmon_ctx->hm_xnvctrl == NULL && hwmon_ctx->hm_sysfs == NULL) if (hwmon_ctx->hm_adl == NULL && hwmon_ctx->hm_nvml == NULL && hwmon_ctx->hm_xnvctrl == NULL && hwmon_ctx->hm_sysfs == NULL)
{ {
hcfree (hm_adapters_adl); FREE_ADAPTERS;
hcfree (hm_adapters_nvapi);
hcfree (hm_adapters_nvml);
hcfree (hm_adapters_xnvctrl);
hcfree (hm_adapters_sysfs);
return 0; return 0;
} }
@ -3752,11 +3813,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
hm_get_utilization_with_device_id (hashcat_ctx, device_id); hm_get_utilization_with_device_id (hashcat_ctx, device_id);
} }
hcfree (hm_adapters_adl); FREE_ADAPTERS;
hcfree (hm_adapters_nvapi);
hcfree (hm_adapters_nvml);
hcfree (hm_adapters_xnvctrl);
hcfree (hm_adapters_sysfs);
/** /**
* powertune on user request * powertune on user request