[vlc-commits] gnutls: fix memory leaks

Rémi Denis-Courmont git at videolan.org
Sat Aug 23 16:35:25 CEST 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Aug 23 17:31:17 2014 +0300| [2c753633d9bdc0266a831e9979cd5f2c06f31d61] | committer: Rémi Denis-Courmont

gnutls: fix memory leaks

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2c753633d9bdc0266a831e9979cd5f2c06f31d61
---

 modules/misc/gnutls.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c
index a09af8a..0af4426 100644
--- a/modules/misc/gnutls.c
+++ b/modules/misc/gnutls.c
@@ -499,7 +499,10 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
 
     vlc_tls_creds_sys_t *sys = malloc (sizeof (*sys));
     if (unlikely(sys == NULL))
-        goto error;
+    {
+        gnutls_Deinit ();
+        return VLC_ENOMEM;
+    }
 
     /* Sets server's credentials */
     val = gnutls_certificate_allocate_credentials (&sys->x509_cred);
@@ -507,7 +510,9 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
     {
         msg_Err (crd, "cannot allocate credentials: %s",
                  gnutls_strerror (val));
-        goto error;
+        free (sys);
+        gnutls_Deinit ();
+        return VLC_ENOMEM;
     }
 
     block_t *certblock = block_FilePath (cert);
@@ -515,7 +520,7 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
     {
         msg_Err (crd, "cannot read certificate chain from %s: %s", cert,
                  vlc_strerror_c(errno));
-        return VLC_EGENERIC;
+        goto error;
     }
 
     block_t *keyblock = block_FilePath (key);
@@ -524,7 +529,7 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
         msg_Err (crd, "cannot read private key from %s: %s", key,
                  vlc_strerror_c(errno));
         block_Release (certblock);
-        return VLC_EGENERIC;
+        goto error;
     }
 
     gnutls_datum_t pub = {
@@ -577,6 +582,7 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
     return VLC_SUCCESS;
 
 error:
+    gnutls_certificate_free_credentials (sys->x509_cred);
     free (sys);
     gnutls_Deinit ();
     return VLC_EGENERIC;



More information about the vlc-commits mailing list