[Help-gnutls] GnuTLS 2.2.1 memory leaks or just bad usage?

Nikos Mavrogiannopoulos nmav at gnutls.org
Sat Feb 16 12:36:46 CET 2008


On Saturday 16 February 2008, Daniel Stenberg wrote:
> Hi again,
>
> When I run valgrind on curl built with GnuTLS and run it like this:
>
> $ valgrind --leak-check=full curl https://www.openssl.org/ -v -k
>
> I get two different leaks reported, and while I'm not done researching
> these I thought I'd post them here in case someone else wants to help out:

Hello,
 Thank you for reporting this. Does the attached patch solve the leaks?

regards,
Nikos
-------------- next part --------------
diff --git a/lib/gnutls_auth.c b/lib/gnutls_auth.c
index 040bf04..bfa015c 100644
--- a/lib/gnutls_auth.c
+++ b/lib/gnutls_auth.c
@@ -394,14 +394,15 @@ _gnutls_auth_info_set (gnutls_session_t session,
 	   */
 	  if (gnutls_auth_get_type (session) != session->key->auth_info_type)
 	    {
+	      _gnutls_free_auth_info (session);
+
 	      session->key->auth_info =
-		gnutls_realloc_fast (session->key->auth_info, size);
+		gnutls_calloc (1, size);
 	      if (session->key->auth_info == NULL)
 		{
 		  gnutls_assert ();
 		  return GNUTLS_E_MEMORY_ERROR;
 		}
-	      memset (session->key->auth_info, 0, size);
 	      session->key->auth_info_type = type;
 	      session->key->auth_info_size = size;
 	    }
diff --git a/lib/gnutls_session.c b/lib/gnutls_session.c
index a1cd173..3048115 100644
--- a/lib/gnutls_session.c
+++ b/lib/gnutls_session.c
@@ -61,12 +61,19 @@ gnutls_session_get_data (gnutls_session_t session,
   *session_data_size = psession.size;
 
   if (psession.size > *session_data_size)
-    return GNUTLS_E_SHORT_MEMORY_BUFFER;
+    {
+      ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
+      goto error;
+    }
 
   if (session_data != NULL)
     memcpy (session_data, psession.data, psession.size);
 
-  return 0;
+  ret = 0;
+
+error:
+  _gnutls_free_datum( &psession);
+  return ret;
 }
 
 /**


More information about the Gnutls-help mailing list