From 9413ed8f56a8eb81f67ab24bba06a01f6ae4c4dc Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 2 Oct 2016 00:00:21 +0200 Subject: [PATCH] Centralize hashcat_ctx memory allocation and deallocation --- src/bitmap.c | 23 +----- src/combinator.c | 10 +-- src/cpt.c | 9 +-- src/debugfile.c | 9 +-- src/dictstat.c | 9 +-- src/folder.c | 9 +-- src/hashcat.c | 183 +++++++++++++++++++++----------------------- src/hashes.c | 26 +------ src/hwmon.c | 20 +---- src/induct.c | 9 +-- src/interface.c | 2 +- src/logfile.c | 9 +-- src/loopback.c | 11 +-- src/mpsp.c | 2 +- src/opencl.c | 9 +-- src/outfile.c | 7 +- src/outfile_check.c | 9 +-- src/potfile.c | 11 +-- src/restore.c | 12 +-- src/rp_cpu.c | 8 +- src/status.c | 6 +- src/straight.c | 12 +-- src/tuningdb.c | 9 +-- src/user_options.c | 4 +- src/wordlist.c | 16 +--- 25 files changed, 136 insertions(+), 298 deletions(-) diff --git a/src/bitmap.c b/src/bitmap.c index 8b428e0ce..a88c5f254 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -133,17 +133,7 @@ void bitmap_ctx_init (bitmap_ctx_t *bitmap_ctx, const user_options_t *user_optio void bitmap_ctx_destroy (bitmap_ctx_t *bitmap_ctx) { - if (bitmap_ctx->enabled == false) - { - myfree (bitmap_ctx); - - return; - } - - bitmap_ctx->bitmap_size = 0; - bitmap_ctx->bitmap_mask = 0; - bitmap_ctx->bitmap_shift1 = 0; - bitmap_ctx->bitmap_shift2 = 0; + if (bitmap_ctx->enabled == false) return; myfree (bitmap_ctx->bitmap_s1_a); myfree (bitmap_ctx->bitmap_s1_b); @@ -154,14 +144,5 @@ void bitmap_ctx_destroy (bitmap_ctx_t *bitmap_ctx) myfree (bitmap_ctx->bitmap_s2_c); myfree (bitmap_ctx->bitmap_s2_d); - bitmap_ctx->bitmap_s1_a = NULL; - bitmap_ctx->bitmap_s1_b = NULL; - bitmap_ctx->bitmap_s1_c = NULL; - bitmap_ctx->bitmap_s1_d = NULL; - bitmap_ctx->bitmap_s2_a = NULL; - bitmap_ctx->bitmap_s2_b = NULL; - bitmap_ctx->bitmap_s2_c = NULL; - bitmap_ctx->bitmap_s2_d = NULL; - - myfree (bitmap_ctx); + memset (bitmap_ctx, 0, sizeof (bitmap_ctx_t)); } diff --git a/src/combinator.c b/src/combinator.c index 563e1111d..a11868716 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -31,13 +31,7 @@ int combinator_ctx_init (combinator_ctx_t *combinator_ctx, const user_options_t void combinator_ctx_destroy (combinator_ctx_t *combinator_ctx) { - if (combinator_ctx->enabled == false) - { - myfree (combinator_ctx); + if (combinator_ctx->enabled == false) return; - return; - } - - myfree (combinator_ctx); + memset (combinator_ctx, 0, sizeof (combinator_ctx_t)); } - diff --git a/src/cpt.c b/src/cpt.c index 41eaa5a1e..0b6f5b688 100644 --- a/src/cpt.c +++ b/src/cpt.c @@ -34,16 +34,11 @@ int cpt_ctx_init (cpt_ctx_t *cpt_ctx, const user_options_t *user_options) void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx) { - if (cpt_ctx->enabled == false) - { - myfree (cpt_ctx); - - return; - } + if (cpt_ctx->enabled == false) return; myfree (cpt_ctx->cpt_buf); - myfree (cpt_ctx); + memset (cpt_ctx, 0, sizeof (cpt_ctx_t)); } void cpt_ctx_reset (cpt_ctx_t *cpt_ctx) diff --git a/src/debugfile.c b/src/debugfile.c index 731f5f711..7769748e9 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -50,19 +50,14 @@ int debugfile_init (debugfile_ctx_t *debugfile_ctx, const user_options_t *user_o void debugfile_destroy (debugfile_ctx_t *debugfile_ctx) { - if (debugfile_ctx->enabled == false) - { - myfree (debugfile_ctx); - - return; - } + if (debugfile_ctx->enabled == false) return; if (debugfile_ctx->filename) { fclose (debugfile_ctx->fp); } - myfree (debugfile_ctx); + memset (debugfile_ctx, 0, sizeof (debugfile_ctx_t)); } void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr, const u32 plain_len) diff --git a/src/dictstat.c b/src/dictstat.c index 6df1dd979..75a9f3379 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -48,17 +48,12 @@ void dictstat_init (dictstat_ctx_t *dictstat_ctx, const user_options_t *user_opt void dictstat_destroy (dictstat_ctx_t *dictstat_ctx) { - if (dictstat_ctx->enabled == false) - { - myfree (dictstat_ctx); - - return; - } + if (dictstat_ctx->enabled == false) return; myfree (dictstat_ctx->filename); myfree (dictstat_ctx->base); - myfree (dictstat_ctx); + memset (dictstat_ctx, 0, sizeof (dictstat_ctx_t)); } void dictstat_read (dictstat_ctx_t *dictstat_ctx, const int comptime) diff --git a/src/folder.c b/src/folder.c index 514b0ce37..fbd6f013c 100644 --- a/src/folder.c +++ b/src/folder.c @@ -415,14 +415,7 @@ void folder_config_destroy (folder_config_t *folder_config) myfree (folder_config->cwd); myfree (folder_config->install_dir); - folder_config->cpath_real = NULL; - folder_config->cwd = NULL; - folder_config->install_dir = NULL; - folder_config->profile_dir = NULL; - folder_config->session_dir = NULL; - folder_config->shared_dir = NULL; - - myfree (folder_config); + memset (folder_config, 0, sizeof (folder_config_t)); } int hc_mkdir (const char *name, int mode) diff --git a/src/hashcat.c b/src/hashcat.c index 608c57ca5..1d96061c7 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -56,6 +56,62 @@ extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT; extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; +static void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx) +{ + hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) mymalloc (sizeof (bitmap_ctx_t)); + hashcat_ctx->combinator_ctx = (combinator_ctx_t *) mymalloc (sizeof (combinator_ctx_t)); + hashcat_ctx->cpt_ctx = (cpt_ctx_t *) mymalloc (sizeof (cpt_ctx_t)); + hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) mymalloc (sizeof (debugfile_ctx_t)); + hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) mymalloc (sizeof (dictstat_ctx_t)); + hashcat_ctx->folder_config = (folder_config_t *) mymalloc (sizeof (folder_config_t)); + hashcat_ctx->hashconfig = (hashconfig_t *) mymalloc (sizeof (hashconfig_t)); + hashcat_ctx->hashes = (hashes_t *) mymalloc (sizeof (hashes_t)); + hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) mymalloc (sizeof (hwmon_ctx_t)); + hashcat_ctx->induct_ctx = (induct_ctx_t *) mymalloc (sizeof (induct_ctx_t)); + hashcat_ctx->logfile_ctx = (logfile_ctx_t *) mymalloc (sizeof (logfile_ctx_t)); + hashcat_ctx->loopback_ctx = (loopback_ctx_t *) mymalloc (sizeof (loopback_ctx_t)); + hashcat_ctx->mask_ctx = (mask_ctx_t *) mymalloc (sizeof (mask_ctx_t)); + hashcat_ctx->opencl_ctx = (opencl_ctx_t *) mymalloc (sizeof (opencl_ctx_t)); + hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) mymalloc (sizeof (outcheck_ctx_t)); + hashcat_ctx->outfile_ctx = (outfile_ctx_t *) mymalloc (sizeof (outfile_ctx_t)); + hashcat_ctx->potfile_ctx = (potfile_ctx_t *) mymalloc (sizeof (potfile_ctx_t)); + hashcat_ctx->restore_ctx = (restore_ctx_t *) mymalloc (sizeof (restore_ctx_t)); + hashcat_ctx->status_ctx = (status_ctx_t *) mymalloc (sizeof (status_ctx_t)); + hashcat_ctx->straight_ctx = (straight_ctx_t *) mymalloc (sizeof (straight_ctx_t)); + hashcat_ctx->tuning_db = (tuning_db_t *) mymalloc (sizeof (tuning_db_t)); + hashcat_ctx->user_options_extra = (user_options_extra_t *) mymalloc (sizeof (user_options_extra_t)); + hashcat_ctx->user_options = (user_options_t *) mymalloc (sizeof (user_options_t)); + hashcat_ctx->wl_data = (wl_data_t *) mymalloc (sizeof (wl_data_t)); +} + +static void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx) +{ + myfree (hashcat_ctx->bitmap_ctx); + myfree (hashcat_ctx->combinator_ctx); + myfree (hashcat_ctx->cpt_ctx); + myfree (hashcat_ctx->debugfile_ctx); + myfree (hashcat_ctx->dictstat_ctx); + myfree (hashcat_ctx->folder_config); + myfree (hashcat_ctx->hashconfig); + myfree (hashcat_ctx->hashes); + myfree (hashcat_ctx->hwmon_ctx); + myfree (hashcat_ctx->induct_ctx); + myfree (hashcat_ctx->logfile_ctx); + myfree (hashcat_ctx->loopback_ctx); + myfree (hashcat_ctx->mask_ctx); + myfree (hashcat_ctx->opencl_ctx); + myfree (hashcat_ctx->outcheck_ctx); + myfree (hashcat_ctx->outfile_ctx); + myfree (hashcat_ctx->potfile_ctx); + myfree (hashcat_ctx->restore_ctx); + myfree (hashcat_ctx->status_ctx); + myfree (hashcat_ctx->straight_ctx); + myfree (hashcat_ctx->tuning_db); + myfree (hashcat_ctx->user_options_extra); + myfree (hashcat_ctx->user_options); + myfree (hashcat_ctx->wl_data); +} + // inner2_loop iterates through wordlists, then calls kernel execution static int inner2_loop (hashcat_ctx_t *hashcat_ctx) @@ -1210,18 +1266,26 @@ static int inner1_loop (hashcat_ctx_t *hashcat_ctx) static int outer_loop (hashcat_ctx_t *hashcat_ctx) { + bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx; + cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; folder_config_t *folder_config = hashcat_ctx->folder_config; + hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + hashes_t *hashes = hashcat_ctx->hashes; hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx; outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; tuning_db_t *tuning_db = hashcat_ctx->tuning_db; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; + wl_data_t *wl_data = hashcat_ctx->wl_data; status_ctx->devices_status = STATUS_INIT; @@ -1241,10 +1305,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * setup variables and buffers depending on hash_mode */ - hashconfig_t *hashconfig = (hashconfig_t *) mymalloc (sizeof (hashconfig_t)); - - hashcat_ctx->hashconfig = hashconfig; - const int rc_hashconfig = hashconfig_init (hashconfig, user_options); if (rc_hashconfig == -1) return -1; @@ -1268,10 +1328,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * load hashes, stage 1 */ - hashes_t *hashes = (hashes_t *) mymalloc (sizeof (hashes_t)); - - hashcat_ctx->hashes = hashes; - const int rc_hashes_init_stage1 = hashes_init_stage1 (hashes, hashconfig, potfile_ctx, outfile_ctx, user_options, restore_ctx->argv[user_options_extra->optind]); if (rc_hashes_init_stage1 == -1) return -1; @@ -1336,40 +1392,24 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * bitmaps */ - bitmap_ctx_t *bitmap_ctx = (bitmap_ctx_t *) mymalloc (sizeof (bitmap_ctx_t)); - - hashcat_ctx->bitmap_ctx = bitmap_ctx; - bitmap_ctx_init (bitmap_ctx, user_options, hashconfig, hashes); /** * cracks-per-time allocate buffer */ - cpt_ctx_t *cpt_ctx = (cpt_ctx_t *) mymalloc (sizeof (cpt_ctx_t)); - - hashcat_ctx->cpt_ctx = cpt_ctx; - cpt_ctx_init (cpt_ctx, user_options); /** * Wordlist allocate buffer */ - wl_data_t *wl_data = (wl_data_t *) mymalloc (sizeof (wl_data_t)); - - hashcat_ctx->wl_data = wl_data; - wl_data_init (wl_data, user_options, hashconfig); /** * straight mode init */ - straight_ctx_t *straight_ctx = (straight_ctx_t *) mymalloc (sizeof (straight_ctx_t)); - - hashcat_ctx->straight_ctx = straight_ctx; - const int rc_straight_init = straight_ctx_init (straight_ctx, user_options); if (rc_straight_init == -1) return -1; @@ -1378,10 +1418,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * straight mode init */ - combinator_ctx_t *combinator_ctx = (combinator_ctx_t *) mymalloc (sizeof (combinator_ctx_t)); - - hashcat_ctx->combinator_ctx = combinator_ctx; - const int rc_combinator_init = combinator_ctx_init (combinator_ctx, user_options); if (rc_combinator_init == -1) return -1; @@ -1390,10 +1426,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * charsets : keep them together for more easy maintainnce */ - mask_ctx_t *mask_ctx = (mask_ctx_t *) mymalloc (sizeof (mask_ctx_t)); - - hashcat_ctx->mask_ctx = mask_ctx; - const int rc_mask_init = mask_ctx_init (mask_ctx, user_options, user_options_extra, folder_config, restore_ctx, hashconfig); if (rc_mask_init == -1) return -1; @@ -1702,12 +1734,31 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) setup_umask (); /** - * status init + * main init */ - status_ctx_t *status_ctx = (status_ctx_t *) mymalloc (sizeof (status_ctx_t)); + hashcat_ctx_init (hashcat_ctx); + + debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + folder_config_t *folder_config = hashcat_ctx->folder_config; + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx; + logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; + loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx; + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; + restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + tuning_db_t *tuning_db = hashcat_ctx->tuning_db; + user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + user_options_t *user_options = hashcat_ctx->user_options; - hashcat_ctx->status_ctx = status_ctx; + /** + * status init + */ const int rc_status_init = status_ctx_init (status_ctx); @@ -1728,20 +1779,12 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) shared_folder = SHARED_FOLDER; #endif - folder_config_t *folder_config = (folder_config_t *) mymalloc (sizeof (folder_config_t)); - - hashcat_ctx->folder_config = folder_config; - folder_config_init (folder_config, install_folder, shared_folder); /** * commandline parameters */ - user_options_t *user_options = (user_options_t *) mymalloc (sizeof (user_options_t)); - - hashcat_ctx->user_options = user_options; - user_options_init (user_options); const int rc_user_options_parse = user_options_parse (user_options, argc, argv); @@ -1770,10 +1813,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * restore */ - restore_ctx_t *restore_ctx = (restore_ctx_t *) mymalloc (sizeof (restore_ctx_t)); - - hashcat_ctx->restore_ctx = restore_ctx; - const int rc_restore_init = restore_ctx_init (restore_ctx, user_options, folder_config, argc, argv); if (rc_restore_init == -1) return -1; @@ -1782,10 +1821,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * process user input */ - user_options_extra_t *user_options_extra = (user_options_extra_t *) mymalloc (sizeof (user_options_extra_t)); - - hashcat_ctx->user_options_extra = user_options_extra; - const int rc_user_options_extra_init = user_options_extra_init (user_options, restore_ctx, user_options_extra); if (rc_user_options_extra_init == -1) return -1; @@ -1811,10 +1846,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * logfile init */ - logfile_ctx_t *logfile_ctx = (logfile_ctx_t *) mymalloc (sizeof (logfile_ctx_t)); - - hashcat_ctx->logfile_ctx = logfile_ctx; - logfile_init (logfile_ctx, user_options, folder_config); logfile_generate_topid (logfile_ctx); @@ -1827,10 +1858,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * tuning db */ - tuning_db_t *tuning_db = (tuning_db_t *) mymalloc (sizeof (tuning_db_t)); - - hashcat_ctx->tuning_db = tuning_db; - const int rc_tuning_db = tuning_db_init (tuning_db, user_options, folder_config); if (rc_tuning_db == -1) return -1; @@ -1839,10 +1866,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * induction directory */ - induct_ctx_t *induct_ctx = (induct_ctx_t *) mymalloc (sizeof (induct_ctx_t)); - - hashcat_ctx->induct_ctx = induct_ctx; - const int rc_induct_ctx_init = induct_ctx_init (induct_ctx, user_options, folder_config, status_ctx); if (rc_induct_ctx_init == -1) return -1; @@ -1851,10 +1874,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * outfile-check directory */ - outcheck_ctx_t *outcheck_ctx = (outcheck_ctx_t *) mymalloc (sizeof (outcheck_ctx_t)); - - hashcat_ctx->outcheck_ctx = outcheck_ctx; - const int rc_outcheck_ctx_init = outcheck_ctx_init (outcheck_ctx, user_options, folder_config); if (rc_outcheck_ctx_init == -1) return -1; @@ -1863,10 +1882,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * outfile itself */ - outfile_ctx_t *outfile_ctx = mymalloc (sizeof (outfile_ctx_t)); - - hashcat_ctx->outfile_ctx = outfile_ctx; - outfile_init (outfile_ctx, user_options); /** @@ -1883,40 +1898,24 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * plus it depends on hash_mode, so we continue using it in outer_loop */ - potfile_ctx_t *potfile_ctx = mymalloc (sizeof (potfile_ctx_t)); - - hashcat_ctx->potfile_ctx = potfile_ctx; - potfile_init (potfile_ctx, user_options, folder_config); /** * dictstat init */ - dictstat_ctx_t *dictstat_ctx = mymalloc (sizeof (dictstat_ctx_t)); - - hashcat_ctx->dictstat_ctx = dictstat_ctx; - dictstat_init (dictstat_ctx, user_options, folder_config); /** * loopback init */ - loopback_ctx_t *loopback_ctx = mymalloc (sizeof (loopback_ctx_t)); - - hashcat_ctx->loopback_ctx = loopback_ctx; - loopback_init (loopback_ctx, user_options); /** * debugfile init */ - debugfile_ctx_t *debugfile_ctx = mymalloc (sizeof (debugfile_ctx_t)); - - hashcat_ctx->debugfile_ctx = debugfile_ctx; - debugfile_init (debugfile_ctx, user_options); /** @@ -1932,10 +1931,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * Init OpenCL library loader */ - opencl_ctx_t *opencl_ctx = (opencl_ctx_t *) mymalloc (sizeof (opencl_ctx_t)); - - hashcat_ctx->opencl_ctx = opencl_ctx; - const int rc_opencl_init = opencl_ctx_init (opencl_ctx, user_options); if (rc_opencl_init == -1) @@ -1962,10 +1957,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) * HM devices: init */ - hwmon_ctx_t *hwmon_ctx = (hwmon_ctx_t *) mymalloc (sizeof (hwmon_ctx_t)); - - hashcat_ctx->hwmon_ctx = hwmon_ctx; - const int rc_hwmon_init = hwmon_ctx_init (hwmon_ctx, user_options, opencl_ctx); if (rc_hwmon_init == -1) @@ -2098,5 +2089,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) status_ctx_destroy (status_ctx); + hashcat_ctx_destroy (hashcat_ctx); + return rc_final; } diff --git a/src/hashes.c b/src/hashes.c index 43dc60073..1d1704c8f 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -1512,31 +1512,7 @@ void hashes_destroy (hashes_t *hashes) myfree (hashes->hash_info); - hashes->hashfile = NULL; - - hashes->hashlist_mode = 0; - hashes->hashlist_format = 0; - - hashes->digests_cnt = 0; - hashes->digests_done = 0; - hashes->digests_saved = 0; - hashes->digests_buf = NULL; - hashes->digests_shown = NULL; - hashes->digests_shown_tmp = NULL; - - hashes->salts_cnt = 0; - hashes->salts_done = 0; - hashes->salts_buf = NULL; - hashes->salts_shown = NULL; - - hashes->esalts_buf = NULL; - - hashes->hashes_cnt = 0; - hashes->hashes_buf = NULL; - - hashes->hash_info = NULL; - - myfree (hashes); + memset (hashes, 0, sizeof (hashes_t)); } void hashes_logger (const hashes_t *hashes, const logfile_ctx_t *logfile_ctx) diff --git a/src/hwmon.c b/src/hwmon.c index 834b9d40b..66bdf32b8 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -1269,12 +1269,7 @@ int hwmon_ctx_init (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_options, void hwmon_ctx_destroy (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_options, const opencl_ctx_t *opencl_ctx) { - if (hwmon_ctx->enabled == false) - { - myfree (hwmon_ctx); - - return; - } + if (hwmon_ctx->enabled == false) return; // reset default fan speed @@ -1416,16 +1411,5 @@ void hwmon_ctx_destroy (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_optio myfree (hwmon_ctx->hm_device); - hwmon_ctx->nvml_power_limit = NULL; - hwmon_ctx->od_power_control_status = NULL; - hwmon_ctx->od_clock_mem_status = NULL; - - hwmon_ctx->hm_device = NULL; - - hwmon_ctx->hm_adl = NULL; - hwmon_ctx->hm_nvml = NULL; - hwmon_ctx->hm_nvapi = NULL; - hwmon_ctx->hm_xnvctrl = NULL; - - myfree (hwmon_ctx); + memset (hwmon_ctx, 0, sizeof (hwmon_ctx_t)); } diff --git a/src/induct.c b/src/induct.c index 3b0719dfa..08e806909 100644 --- a/src/induct.c +++ b/src/induct.c @@ -117,12 +117,7 @@ void induct_ctx_cleanup (induct_ctx_t *induct_ctx) void induct_ctx_destroy (induct_ctx_t *induct_ctx) { - if (induct_ctx->enabled == false) - { - myfree (induct_ctx); - - return; - } + if (induct_ctx->enabled == false) return; if (rmdir (induct_ctx->root_directory) == -1) { @@ -144,5 +139,5 @@ void induct_ctx_destroy (induct_ctx_t *induct_ctx) myfree (induct_ctx->root_directory); - myfree (induct_ctx); + memset (induct_ctx, 0, sizeof (induct_ctx_t)); } diff --git a/src/interface.c b/src/interface.c index 3bc75efde..b7732a9db 100644 --- a/src/interface.c +++ b/src/interface.c @@ -20008,7 +20008,7 @@ int hashconfig_init (hashconfig_t *hashconfig, const user_options_t *user_option void hashconfig_destroy (hashconfig_t *hashconfig) { - myfree (hashconfig); + memset (hashconfig, 0, sizeof (hashconfig_t)); } u32 hashconfig_enforce_kernel_threads (const hashconfig_t *hashconfig, const hc_device_param_t *device_param) diff --git a/src/logfile.c b/src/logfile.c index 209e7b100..94a5a3fce 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -78,16 +78,11 @@ void logfile_init (logfile_ctx_t *logfile_ctx, const user_options_t *user_option void logfile_destroy (logfile_ctx_t *logfile_ctx) { - if (logfile_ctx->enabled == false) - { - myfree (logfile_ctx); - - return; - } + if (logfile_ctx->enabled == false) return; myfree (logfile_ctx->logfile); myfree (logfile_ctx->topid); myfree (logfile_ctx->subid); - myfree (logfile_ctx); + memset (logfile_ctx, 0, sizeof (logfile_ctx_t)); } diff --git a/src/loopback.c b/src/loopback.c index b67e2a3f5..6b74a9cbf 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -32,16 +32,9 @@ void loopback_init (loopback_ctx_t *loopback_ctx, const user_options_t *user_opt void loopback_destroy (loopback_ctx_t *loopback_ctx) { - if (loopback_ctx->enabled == false) - { - myfree (loopback_ctx); - - return; - } - - myfree (loopback_ctx->filename); + if (loopback_ctx->enabled == false) return; - myfree (loopback_ctx); + memset (loopback_ctx, 0, sizeof (loopback_ctx_t)); } int loopback_write_open (loopback_ctx_t *loopback_ctx, const induct_ctx_t *induct_ctx) diff --git a/src/mpsp.c b/src/mpsp.c index ad5065236..24b6dd871 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -1119,7 +1119,7 @@ void mask_ctx_destroy (mask_ctx_t *mask_ctx) myfree (mask_ctx->mfs); - myfree (mask_ctx); + memset (mask_ctx, 0, sizeof (mask_ctx_t)); } int mask_ctx_parse_maskfile (mask_ctx_t *mask_ctx, user_options_t *user_options, const hashconfig_t *hashconfig) diff --git a/src/opencl.c b/src/opencl.c index d5a53c993..80c882173 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -1512,12 +1512,7 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_option void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx) { - if (opencl_ctx->enabled == false) - { - myfree (opencl_ctx); - - return; - } + if (opencl_ctx->enabled == false) return; myfree (opencl_ctx->devices_param); @@ -1529,7 +1524,7 @@ void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx) myfree (opencl_ctx->platform_devices); - myfree (opencl_ctx); + memset (opencl_ctx, 0, sizeof (opencl_ctx_t)); } int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, const int comptime) diff --git a/src/outfile.c b/src/outfile.c index c41570eaf..dadda5bc0 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -30,12 +30,7 @@ void outfile_init (outfile_ctx_t *outfile_ctx, const user_options_t *user_option void outfile_destroy (outfile_ctx_t *outfile_ctx) { - outfile_ctx->fp = NULL; - outfile_ctx->filename = NULL; - outfile_ctx->outfile_format = 0; - outfile_ctx->outfile_autohex = 0; - - myfree (outfile_ctx); + memset (outfile_ctx, 0, sizeof (outfile_ctx_t)); } void outfile_format_plain (outfile_ctx_t *outfile_ctx, const unsigned char *plain_ptr, const uint plain_len) diff --git a/src/outfile_check.c b/src/outfile_check.c index c706ffa06..63ad6f505 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -374,12 +374,7 @@ int outcheck_ctx_init (outcheck_ctx_t *outcheck_ctx, const user_options_t *user_ void outcheck_ctx_destroy (outcheck_ctx_t *outcheck_ctx) { - if (outcheck_ctx->enabled == false) - { - myfree (outcheck_ctx); - - return; - } + if (outcheck_ctx->enabled == false) return; if (rmdir (outcheck_ctx->root_directory) == -1) { @@ -401,5 +396,5 @@ void outcheck_ctx_destroy (outcheck_ctx_t *outcheck_ctx) myfree (outcheck_ctx->root_directory); - myfree (outcheck_ctx); + memset (outcheck_ctx, 0, sizeof (outcheck_ctx_t)); } diff --git a/src/potfile.c b/src/potfile.c index 6259fadb1..bd6f12b00 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -181,16 +181,9 @@ void potfile_init (potfile_ctx_t *potfile_ctx, const user_options_t *user_option void potfile_destroy (potfile_ctx_t *potfile_ctx) { - if (potfile_ctx->enabled == false) - { - myfree (potfile_ctx); - - return; - } - - myfree (potfile_ctx->filename); + if (potfile_ctx->enabled == false) return; - myfree (potfile_ctx); + memset (potfile_ctx, 0, sizeof (potfile_ctx_t)); } void potfile_format_plain (potfile_ctx_t *potfile_ctx, const unsigned char *plain_ptr, const uint plain_len) diff --git a/src/restore.c b/src/restore.c index ef707d0b5..7c3c1ffb3 100644 --- a/src/restore.c +++ b/src/restore.c @@ -408,15 +408,7 @@ void restore_ctx_destroy (restore_ctx_t *restore_ctx) myfree (restore_ctx->rd); - if (restore_ctx->enabled == false) - { - myfree (restore_ctx); - - return; - } - - restore_ctx->argc = 0; - restore_ctx->argv = NULL; + if (restore_ctx->enabled == false) return; - myfree (restore_ctx); + memset (restore_ctx, 0, sizeof (restore_ctx_t)); } diff --git a/src/rp_cpu.c b/src/rp_cpu.c index 4109a1ab5..533026936 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -15,22 +15,22 @@ #define NEXT_RULEPOS(rp) if (++(rp) == rule_len) return (RULE_RC_SYNTAX_ERROR) #define NEXT_RPTOI(r,rp,up) if (((up) = conv_ctoi ((r)[(rp)])) == -1) return (RULE_RC_SYNTAX_ERROR) -inline void MANGLE_TOGGLE_AT (char *arr, const int pos) +static void MANGLE_TOGGLE_AT (char *arr, const int pos) { if (class_alpha (arr[pos])) arr[pos] ^= 0x20; } -inline void MANGLE_LOWER_AT (char *arr, const int pos) +static void MANGLE_LOWER_AT (char *arr, const int pos) { if (class_upper (arr[pos])) arr[pos] ^= 0x20; } -inline void MANGLE_UPPER_AT (char *arr, const int pos) +static void MANGLE_UPPER_AT (char *arr, const int pos) { if (class_lower (arr[pos])) arr[pos] ^= 0x20; } -inline void MANGLE_SWITCH (char *arr, const int l, const int r) +static void MANGLE_SWITCH (char *arr, const int l, const int r) { char c = arr[r]; arr[r] = arr[l]; diff --git a/src/status.c b/src/status.c index 8f8df2e5b..2466b27b0 100644 --- a/src/status.c +++ b/src/status.c @@ -1237,6 +1237,10 @@ void status_progress_destroy (status_ctx_t *status_ctx) myfree (status_ctx->words_progress_done); myfree (status_ctx->words_progress_rejected); myfree (status_ctx->words_progress_restored); + + status_ctx->words_progress_done = NULL; + status_ctx->words_progress_rejected = NULL; + status_ctx->words_progress_restored = NULL; } void status_progress_reset (status_ctx_t *status_ctx, const hashes_t *hashes) @@ -1273,5 +1277,5 @@ void status_ctx_destroy (status_ctx_t *status_ctx) hc_thread_mutex_delete (status_ctx->mux_display); hc_thread_mutex_delete (status_ctx->mux_hwmon); - myfree (status_ctx); + memset (status_ctx, 0, sizeof (status_ctx_t)); } diff --git a/src/straight.c b/src/straight.c index f0cd718fe..64252e5af 100644 --- a/src/straight.c +++ b/src/straight.c @@ -65,12 +65,7 @@ int straight_ctx_init (straight_ctx_t *straight_ctx, const user_options_t *user_ void straight_ctx_destroy (straight_ctx_t *straight_ctx) { - if (straight_ctx->enabled == false) - { - myfree (straight_ctx); - - return; - } + if (straight_ctx->enabled == false) return; for (u32 dict_pos = 0; dict_pos < straight_ctx->dicts_cnt; dict_pos++) { @@ -81,10 +76,7 @@ void straight_ctx_destroy (straight_ctx_t *straight_ctx) myfree (straight_ctx->kernel_rules_buf); - straight_ctx->kernel_rules_buf = NULL; - straight_ctx->kernel_rules_cnt = 0; - - myfree (straight_ctx); + memset (straight_ctx, 0, sizeof (straight_ctx_t)); } void straight_append_dict (straight_ctx_t *straight_ctx, const char *dict) diff --git a/src/tuningdb.c b/src/tuningdb.c index 9d50b4b49..8e82e5a68 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -241,12 +241,7 @@ int tuning_db_init (tuning_db_t *tuning_db, const user_options_t *user_options, void tuning_db_destroy (tuning_db_t *tuning_db) { - if (tuning_db->enabled == false) - { - myfree (tuning_db); - - return; - } + if (tuning_db->enabled == false) return; int i; @@ -268,7 +263,7 @@ void tuning_db_destroy (tuning_db_t *tuning_db) myfree (tuning_db->alias_buf); myfree (tuning_db->entry_buf); - myfree (tuning_db); + memset (tuning_db, 0, sizeof (tuning_db_t)); } tuning_db_entry_t *tuning_db_search (const tuning_db_t *tuning_db, const char *device_name, const cl_device_type device_type, int attack_mode, const int hash_type) diff --git a/src/user_options.c b/src/user_options.c index 27135c53a..1d9c5af21 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -193,7 +193,7 @@ void user_options_destroy (user_options_t *user_options) { myfree (user_options->rp_files); - myfree (user_options); + memset (user_options, 0, sizeof (user_options_t)); } int user_options_parse (user_options_t *user_options, int argc, char **argv) @@ -986,7 +986,7 @@ int user_options_extra_init (user_options_t *user_options, restore_ctx_t *restor void user_options_extra_destroy (user_options_extra_t *user_options_extra) { - myfree (user_options_extra); + memset (user_options_extra, 0, sizeof (user_options_extra_t)); } void user_options_logger (const user_options_t *user_options, const logfile_ctx_t *logfile_ctx) diff --git a/src/wordlist.c b/src/wordlist.c index 5a18deb21..81e719005 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -439,21 +439,9 @@ void wl_data_init (wl_data_t *wl_data, const user_options_t *user_options, const void wl_data_destroy (wl_data_t *wl_data) { - if (wl_data->enabled == false) - { - myfree (wl_data); - - return; - } + if (wl_data->enabled == false) return; myfree (wl_data->buf); - wl_data->func = NULL; - wl_data->buf = NULL; - wl_data->avail = 0; - wl_data->incr = 0; - wl_data->cnt = 0; - wl_data->pos = 0; - - myfree (wl_data); + memset (wl_data, 0, sizeof (wl_data_t)); }