From 0cce17d268d2e556e4544f5884d2c43569586403 Mon Sep 17 00:00:00 2001 From: jsteube Date: Tue, 30 May 2017 12:15:55 +0200 Subject: [PATCH] Eventual fix for #1263 --- include/status.h | 2 +- src/memory.c | 1 - src/status.c | 51 ++++++++++++++++++++++++++++++++++-------------- src/terminal.c | 24 +++++++++++++++-------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/include/status.h b/include/status.h index e3556f331..7f0501e70 100644 --- a/include/status.h +++ b/include/status.h @@ -91,6 +91,6 @@ void status_progress_reset (hashcat_ctx_t *hashcat_ctx); int status_ctx_init (hashcat_ctx_t *hashcat_ctx); void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx); -void status_status_destroy (hashcat_status_t *status_ctx); +void status_status_destroy (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *status_ctx); #endif // _STATUS_H diff --git a/src/memory.c b/src/memory.c index 54d323e95..1626a3acf 100644 --- a/src/memory.c +++ b/src/memory.c @@ -73,5 +73,4 @@ void hcfree (void *ptr) if (ptr == NULL) return; free (ptr); - ptr = NULL; } diff --git a/src/status.c b/src/status.c index 6087fa410..0497641f6 100644 --- a/src/status.c +++ b/src/status.c @@ -1807,26 +1807,47 @@ void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx) memset (status_ctx, 0, sizeof (status_ctx_t)); } -void status_status_destroy (hashcat_status_t *status_ctx) + +void status_status_destroy (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status) { - if (NULL == status_ctx) return; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx == NULL) return; + + if (status_ctx->accessible == false) return; - hcfree (status_ctx->session); - hcfree (status_ctx->time_estimated_absolute); - hcfree (status_ctx->time_estimated_relative); - hcfree (status_ctx->time_started_absolute); - hcfree (status_ctx->time_started_relative); - hcfree (status_ctx->speed_sec_all); - hcfree (status_ctx->guess_base); - hcfree (status_ctx->guess_mod); - hcfree (status_ctx->guess_charset); - hcfree (status_ctx->cpt); + hcfree (hashcat_status->session); + hcfree (hashcat_status->time_estimated_absolute); + hcfree (hashcat_status->time_estimated_relative); + hcfree (hashcat_status->time_started_absolute); + hcfree (hashcat_status->time_started_relative); + hcfree (hashcat_status->speed_sec_all); + hcfree (hashcat_status->guess_base); + hcfree (hashcat_status->guess_mod); + hcfree (hashcat_status->guess_charset); + hcfree (hashcat_status->cpt); - for (int device_id = 0; device_id < status_ctx->device_info_cnt; device_id++) + hashcat_status->session = NULL; + hashcat_status->time_estimated_absolute = NULL; + hashcat_status->time_estimated_relative = NULL; + hashcat_status->time_started_absolute = NULL; + hashcat_status->time_started_relative = NULL; + hashcat_status->speed_sec_all = NULL; + hashcat_status->guess_base = NULL; + hashcat_status->guess_mod = NULL; + hashcat_status->guess_charset = NULL; + hashcat_status->cpt = NULL; + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) { - device_info_t *device_info = status_ctx->device_info_buf + device_id; + device_info_t *device_info = hashcat_status->device_info_buf + device_id; + hcfree (device_info->speed_sec_dev); hcfree (device_info->guess_candidates_dev); hcfree (device_info->hwmon_dev); + + device_info->speed_sec_dev = NULL; + device_info->guess_candidates_dev = NULL; + device_info->hwmon_dev = NULL; } -} \ No newline at end of file +} diff --git a/src/terminal.c b/src/terminal.c index 9fe95aeb0..4988225b3 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -692,7 +692,8 @@ void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) fflush (stdout); - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1106,7 +1107,8 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1136,7 +1138,8 @@ void status_benchmark_machine_readable (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, "%d:%u:%d:%d:%.2f:%" PRIu64, device_id + 1, hash_mode, device_info->corespeed_dev, device_info->memoryspeed_dev, device_info->exec_msec_dev, (u64) (device_info->hashes_msec_dev_benchmark * 1000)); } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1181,7 +1184,8 @@ void status_benchmark (hashcat_ctx_t *hashcat_ctx) hashcat_status->speed_sec_all); } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1207,7 +1211,8 @@ void status_speed_machine_readable (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, "%d:%" PRIu64, device_id + 1, (u64) (device_info->hashes_msec_dev_benchmark * 1000)); } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1252,7 +1257,8 @@ void status_speed (hashcat_ctx_t *hashcat_ctx) hashcat_status->speed_sec_all); } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1278,7 +1284,8 @@ void status_progress_machine_readable (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, "%d:%d:%0.2f", device_id + 1, device_info->progress_dev, device_info->runtime_msec_dev); } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); } @@ -1326,6 +1333,7 @@ void status_progress (hashcat_ctx_t *hashcat_ctx) device_info->runtime_msec_dev); } - status_status_destroy (hashcat_status); + status_status_destroy (hashcat_ctx, hashcat_status); + hcfree (hashcat_status); }