summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-04-08 18:38:05 +0200
committerSimon Josefsson <simon@josefsson.org>2008-04-08 18:38:05 +0200
commit230559c9ed014657079d084ea5a7682f7eb6c193 (patch)
tree4cec59773b676faea516a356ae76ea48d0cfe143
parent292f66309ef05cf935ca73ce99f516222642ce41 (diff)
downloadgnutls-230559c9ed014657079d084ea5a7682f7eb6c193.tar.gz
Fix mem leak on errors.
-rw-r--r--lib/gnutls_psk_netconf.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/gnutls_psk_netconf.c b/lib/gnutls_psk_netconf.c
index 8ffbb99455..8e77806d87 100644
--- a/lib/gnutls_psk_netconf.c
+++ b/lib/gnutls_psk_netconf.c
@@ -63,14 +63,6 @@ gnutls_psk_netconf_derive_key (const char *password,
*
*/
- innerlen = sha1len + hintlen;
- inner = gnutls_malloc (innerlen);
- if (inner == NULL)
- {
- gnutls_assert ();
- return GNUTLS_E_MEMORY_ERROR;
- }
-
rc = _gnutls_hash_init (&dig, GNUTLS_DIG_SHA1);
if (rc)
{
@@ -82,6 +74,7 @@ gnutls_psk_netconf_derive_key (const char *password,
if (rc)
{
gnutls_assert ();
+ _gnutls_hash_deinit (&dig, NULL);
return rc;
}
@@ -89,6 +82,7 @@ gnutls_psk_netconf_derive_key (const char *password,
if (rc)
{
gnutls_assert ();
+ _gnutls_hash_deinit (&dig, NULL);
return rc;
}
@@ -96,10 +90,18 @@ gnutls_psk_netconf_derive_key (const char *password,
if (rc)
{
gnutls_assert ();
+ _gnutls_hash_deinit (&dig, NULL);
return rc;
}
+ innerlen = sha1len + hintlen;
+ inner = gnutls_malloc (innerlen);
_gnutls_hash_deinit (&dig, inner);
+ if (inner == NULL)
+ {
+ gnutls_assert ();
+ return GNUTLS_E_MEMORY_ERROR;
+ }
memcpy (inner + sha1len, psk_identity_hint, hintlen);
@@ -107,17 +109,21 @@ gnutls_psk_netconf_derive_key (const char *password,
if (rc)
{
gnutls_assert ();
+ gnutls_free (inner);
return rc;
}
rc = _gnutls_hash (&dig, inner, innerlen);
+ gnutls_free (inner);
if (rc)
{
gnutls_assert ();
+ gnutls_hash_deinit (&dig, NULL);
return rc;
}
output_key->data = gnutls_malloc (sha1len);
+ _gnutls_hash_deinit (&dig, output_key->data);
if (output_key->data == NULL)
{
gnutls_assert ();
@@ -125,8 +131,6 @@ gnutls_psk_netconf_derive_key (const char *password,
}
output_key->size = sha1len;
- _gnutls_hash_deinit (&dig, output_key->data);
-
return 0;
}