1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-23 07:08:19 +00:00

fix some memory leaks

This commit is contained in:
Gabriele Gristina 2019-07-10 17:27:45 +02:00
parent a7fd1e40f8
commit 4b871646fe
6 changed files with 76 additions and 8 deletions

View File

@ -71,6 +71,8 @@ int benchmark_next (hashcat_ctx_t *hashcat_ctx)
cur = hash_mode + 1;
hcfree (modulefile);
return hash_mode;
}
}

View File

@ -2996,6 +2996,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "socket: %s\n", strerror (errno));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3006,6 +3008,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "setsockopt: %s\n", strerror (errno));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3013,6 +3017,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "setsockopt: %s\n", strerror (errno));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
#else
@ -3054,6 +3060,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s: %s\n", listen_host, gai_strerror (rc_getaddrinfo));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
}
@ -3062,6 +3070,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "bind: %s\n", strerror (errno));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3069,6 +3079,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "listen: %s\n", strerror (errno));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3078,6 +3090,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3090,11 +3104,15 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
if (brain_server_read_hash_dumps (brain_server_dbs, ".") == false)
{
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3105,11 +3123,15 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
if (brain_server_read_attack_dumps (brain_server_dbs, ".") == false)
{
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3119,6 +3141,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3135,6 +3159,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3163,6 +3189,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3185,6 +3213,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
{
brain_logging (stderr, 0, "signal: %s\n", strerror (errno));
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3258,11 +3288,15 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
if (brain_server_write_hash_dumps (brain_server_dbs, ".") == false)
{
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
if (brain_server_write_attack_dumps (brain_server_dbs, ".") == false)
{
if (brain_password == NULL) hcfree (auth_password);
return -1;
}
@ -3287,6 +3321,8 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
hcfree (brain_server_client_options);
if (brain_password == NULL) hcfree (auth_password);
close (server_fd);
#if defined (_WIN)

View File

@ -168,7 +168,12 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
iconv_ctx = iconv_open (user_options->encoding_to, user_options->encoding_from);
if (iconv_ctx == (iconv_t) -1) return -1;
if (iconv_ctx == (iconv_t) -1)
{
hcfree (buf);
return -1;
}
iconv_tmp = (char *) hcmalloc (HCBUFSIZ_TINY);
}

View File

@ -20,12 +20,12 @@ static int sort_by_src_len (const void *p1, const void *p2)
bool initialize_keyboard_layout_mapping (const char *filename, keyboard_layout_mapping_t *keyboard_layout_mapping, int *keyboard_layout_mapping_cnt)
{
char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
HCFILE fp;
if (hc_fopen (&fp, filename, "r") == false) return false;
char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
int maps_cnt = 0;
while (!hc_feof (&fp))

View File

@ -1062,8 +1062,12 @@ int main (int argc, char **argv)
const int rc_hashcat_init = hashcat_init (hashcat_ctx, event);
if (rc_hashcat_init == -1) return -1;
if (rc_hashcat_init == -1)
{
hcfree (hashcat_ctx);
return -1;
}
// install and shared folder need to be set to recognize "make install" use
const char *install_folder = NULL;
@ -1081,17 +1085,32 @@ int main (int argc, char **argv)
const int rc_options_init = user_options_init (hashcat_ctx);
if (rc_options_init == -1) return -1;
if (rc_options_init == -1)
{
hcfree (hashcat_ctx);
return -1;
}
// parse commandline parameters and check them
const int rc_options_getopt = user_options_getopt (hashcat_ctx, argc, argv);
if (rc_options_getopt == -1) return -1;
if (rc_options_getopt == -1)
{
hcfree (hashcat_ctx);
return -1;
}
const int rc_options_sanity = user_options_sanity (hashcat_ctx);
if (rc_options_sanity == -1) return -1;
if (rc_options_sanity == -1)
{
hcfree (hashcat_ctx);
return -1;
}
// some early exits
@ -1102,6 +1121,8 @@ int main (int argc, char **argv)
{
const int rc = brain_server (user_options->brain_host, user_options->brain_port, user_options->brain_password, user_options->brain_session_whitelist);
hcfree (hashcat_ctx);
return rc;
}
#endif
@ -1110,6 +1131,8 @@ int main (int argc, char **argv)
{
printf ("%s\n", VERSION_TAG);
hcfree (hashcat_ctx);
return 0;
}
@ -1167,7 +1190,7 @@ int main (int argc, char **argv)
hashcat_destroy (hashcat_ctx);
free (hashcat_ctx);
hcfree (hashcat_ctx);
return rc_final;
}

View File

@ -106,6 +106,8 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx)
hc_fclose (&fp);
hcfree (buf);
return -1;
}