From d24a6198e8006d508336180bec35ea94132c87a4 Mon Sep 17 00:00:00 2001 From: Christopher Schmitt Date: Thu, 18 May 2017 10:14:25 -0400 Subject: [PATCH 1/3] first pass at free'ing hashcat_status_t --- include/status.h | 2 ++ src/memory.c | 1 + src/status.c | 25 +++++++++++++++++++++++++ src/terminal.c | 8 ++++++++ 4 files changed, 36 insertions(+) diff --git a/include/status.h b/include/status.h index e73421608..e3556f331 100644 --- a/include/status.h +++ b/include/status.h @@ -91,4 +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); + #endif // _STATUS_H diff --git a/src/memory.c b/src/memory.c index 1626a3acf..54d323e95 100644 --- a/src/memory.c +++ b/src/memory.c @@ -73,4 +73,5 @@ void hcfree (void *ptr) if (ptr == NULL) return; free (ptr); + ptr = NULL; } diff --git a/src/status.c b/src/status.c index 336aac743..7d6de613e 100644 --- a/src/status.c +++ b/src/status.c @@ -1806,3 +1806,28 @@ 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) +{ + if (NULL == status_ctx) + 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); + + for (int device_id = 0; device_id < status_ctx->device_info_cnt; device_id++) + { + device_info_t *device_info = status_ctx->device_info_buf + device_id; + hcfree(device_info->speed_sec_dev); + hcfree(device_info->guess_candidates_dev); + hcfree(device_info->hwmon_dev); + } +} \ No newline at end of file diff --git a/src/terminal.c b/src/terminal.c index 31bf2de79..9fe95aeb0 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -692,6 +692,7 @@ void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) fflush (stdout); + status_status_destroy (hashcat_status); hcfree (hashcat_status); } @@ -1105,6 +1106,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } } + status_status_destroy (hashcat_status); hcfree (hashcat_status); } @@ -1134,6 +1136,7 @@ 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); hcfree (hashcat_status); } @@ -1178,6 +1181,7 @@ void status_benchmark (hashcat_ctx_t *hashcat_ctx) hashcat_status->speed_sec_all); } + status_status_destroy (hashcat_status); hcfree (hashcat_status); } @@ -1203,6 +1207,7 @@ 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); hcfree (hashcat_status); } @@ -1247,6 +1252,7 @@ void status_speed (hashcat_ctx_t *hashcat_ctx) hashcat_status->speed_sec_all); } + status_status_destroy (hashcat_status); hcfree (hashcat_status); } @@ -1272,6 +1278,7 @@ 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); hcfree (hashcat_status); } @@ -1319,5 +1326,6 @@ void status_progress (hashcat_ctx_t *hashcat_ctx) device_info->runtime_msec_dev); } + status_status_destroy (hashcat_status); hcfree (hashcat_status); } From b5f5591b1a19313e7fdd80e878e7f682811bad9a Mon Sep 17 00:00:00 2001 From: Christopher Schmitt Date: Thu, 18 May 2017 10:36:14 -0400 Subject: [PATCH 2/3] main_monitor_status_refresh shouldnt call status_display if status_ctx is not accessible --- src/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.c b/src/main.c index 615848c42..10a8dd6c0 100644 --- a/src/main.c +++ b/src/main.c @@ -717,6 +717,9 @@ static void main_monitor_status_refresh (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx { const user_options_t *user_options = hashcat_ctx->user_options; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->accessible == false) return; if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { From efd18121d57349194fc76e83b2f1d6e7d4dee3f8 Mon Sep 17 00:00:00 2001 From: Christopher Schmitt Date: Fri, 19 May 2017 08:09:14 -0400 Subject: [PATCH 3/3] Review/Style Changes --- docs/changes.txt | 1 + src/status.c | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 12daa60f2..17447f2d4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -37,6 +37,7 @@ - Fixed a missing type specifier in a function declaration of the RACF kernel - Fixed a condition that caused a hybrid attack using a maskfile to not select all wordlists from a wordlist folder +- Fixed a memory leak that is present when a user is periodically printing hashcat status (using --status-timer) ## ## Technical diff --git a/src/status.c b/src/status.c index 7d6de613e..6087fa410 100644 --- a/src/status.c +++ b/src/status.c @@ -1809,25 +1809,24 @@ void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx) void status_status_destroy (hashcat_status_t *status_ctx) { - if (NULL == status_ctx) - return; + if (NULL == status_ctx) 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 (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); for (int device_id = 0; device_id < status_ctx->device_info_cnt; device_id++) { device_info_t *device_info = status_ctx->device_info_buf + device_id; - hcfree(device_info->speed_sec_dev); - hcfree(device_info->guess_candidates_dev); - hcfree(device_info->hwmon_dev); + hcfree (device_info->speed_sec_dev); + hcfree (device_info->guess_candidates_dev); + hcfree (device_info->hwmon_dev); } } \ No newline at end of file