From 1c9aa258861f927bf794b04b77be350b39428333 Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 23 Sep 2016 21:50:35 +0200 Subject: [PATCH] Fix some memory leaks at shutdown --- include/user_options.h | 2 ++ src/hashcat.c | 44 ++++++++++++++++++++---------------------- src/user_options.c | 5 +++++ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/include/user_options.h b/include/user_options.h index 677cd29b6..75e405ac8 100644 --- a/include/user_options.h +++ b/include/user_options.h @@ -253,6 +253,8 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv int user_options_extra_init (user_options_t *user_options, int myargc, char **myargv, user_options_extra_t *user_options_extra); +void user_options_extra_destroy (user_options_extra_t *user_options_extra); + void user_options_logger (const user_options_t *user_options, const logfile_ctx_t *logfile_ctx); #endif // _USER_OPTIONS_H diff --git a/src/hashcat.c b/src/hashcat.c index 65734e873..96a60b530 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -307,20 +307,6 @@ int main (int argc, char **argv) return 0; } - /** - * logfile init - */ - - logfile_ctx_t *logfile_ctx = (logfile_ctx_t *) mymalloc (sizeof (logfile_ctx_t)); - - data.logfile_ctx = logfile_ctx; - - logfile_init (logfile_ctx, user_options, folder_config); - - logfile_generate_topid (logfile_ctx); - - logfile_top_msg ("START"); - /** * process user input */ @@ -337,6 +323,20 @@ int main (int argc, char **argv) if (rc_user_options_sanity == -1) return -1; + /** + * logfile init + */ + + logfile_ctx_t *logfile_ctx = (logfile_ctx_t *) mymalloc (sizeof (logfile_ctx_t)); + + data.logfile_ctx = logfile_ctx; + + logfile_init (logfile_ctx, user_options, folder_config); + + logfile_generate_topid (logfile_ctx); + + logfile_top_msg ("START"); + user_options_logger (user_options, logfile_ctx); /** @@ -3724,27 +3724,19 @@ int main (int argc, char **argv) // free memory - local_free (hashconfig); - local_free (eff_restore_file); local_free (new_restore_file); local_free (rd); - // tuning db + hashconfig_destroy (hashconfig); tuning_db_destroy (tuning_db); - // induction directory - induct_ctx_destroy (induct_ctx); - // outfile-check directory - outcheck_ctx_destroy (outcheck_ctx); - // shutdown - time_t proc_stop; time (&proc_stop); @@ -3756,6 +3748,8 @@ int main (int argc, char **argv) logfile_destroy (logfile_ctx); + // shutdown + if (user_options->quiet == false) log_info_nn ("Started: %s", ctime (&proc_start)); if (user_options->quiet == false) log_info_nn ("Stopped: %s", ctime (&proc_stop)); @@ -3770,5 +3764,9 @@ int main (int argc, char **argv) folder_config_destroy (folder_config); + user_options_extra_destroy (user_options_extra); + + user_options_destroy (user_options); + return rc_final; } diff --git a/src/user_options.c b/src/user_options.c index 410ff8df8..9df7c1daf 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -874,6 +874,11 @@ int user_options_extra_init (user_options_t *user_options, int myargc, char **my return 0; } +void user_options_extra_destroy (user_options_extra_t *user_options_extra) +{ + myfree (user_options_extra); +} + void user_options_logger (const user_options_t *user_options, const logfile_ctx_t *logfile_ctx) { logfile_top_uint (user_options->benchmark);