diff options
author | Simon Josefsson <simon@josefsson.org> | 2007-05-02 09:47:05 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2007-05-02 09:47:05 +0000 |
commit | 0e29dc8ad00c6b43b81bdd0ff6d214351dbcd8f0 (patch) | |
tree | a02b17ad7ab22926713a2bcf75849594c7502a9b /pkcs11 | |
parent | 565e8e0b7c7cabc0298f01fb2daed75fc39acf5e (diff) | |
download | gnutls-0e29dc8ad00c6b43b81bdd0ff6d214351dbcd8f0.tar.gz |
Fix mem leaks.
Diffstat (limited to 'pkcs11')
-rw-r--r-- | pkcs11/gnutls_pkcs11.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/pkcs11/gnutls_pkcs11.c b/pkcs11/gnutls_pkcs11.c index ec46d346a7..b1de09c5b3 100644 --- a/pkcs11/gnutls_pkcs11.c +++ b/pkcs11/gnutls_pkcs11.c @@ -427,38 +427,44 @@ search_certificates (char *const *pkcs11_keys, else { _gnutls_debug_log("Skipping certificate\n"); + gnutls_free (pValueTemplate[0].pValue); + gnutls_free (pValueTemplate[1].pValue); continue; } - tmplist = realloc (*cert_list, *ncerts + 1); + gnutls_free (pValueTemplate[0].pValue); + + tmplist = gnutls_realloc (*cert_list, sizeof (**cert_list) + * (*ncerts + 1)); if (!tmplist) { gnutls_assert (); - gnutls_free (pValueTemplate[0].pValue); gnutls_free (pValueTemplate[1].pValue); return GNUTLS_E_MEMORY_ERROR; } *cert_list = tmplist; - ret = gnutls_x509_crt_init (&tmplist[*ncerts]); + ret = gnutls_x509_crt_init (&(*cert_list)[*ncerts]); if (ret != GNUTLS_E_SUCCESS) { gnutls_assert (); - gnutls_free (pValueTemplate[0].pValue); + gnutls_free (*cert_list); gnutls_free (pValueTemplate[1].pValue); return ret; } - ret = gnutls_x509_crt_import (tmplist[*ncerts], + ret = gnutls_x509_crt_import ((*cert_list)[*ncerts], &cert, GNUTLS_X509_FMT_DER); if (ret != GNUTLS_E_SUCCESS) { gnutls_assert (); - gnutls_free (pValueTemplate[0].pValue); + gnutls_free (*cert_list); gnutls_free (pValueTemplate[1].pValue); return ret; } + gnutls_free (pValueTemplate[1].pValue); + (*ncerts)++; } } @@ -492,6 +498,7 @@ get_certificates (gnutls_x509_crt_t ** cert_list, CK_RV rv; int ret; char **pkcs11_keys; + size_t i; ret = startup_pkcs11 (&ulSlotCount, &pSlotList); if (ret < 0) @@ -506,6 +513,13 @@ get_certificates (gnutls_x509_crt_t ** cert_list, if (ret < 0) goto out; + if (pkcs11_keys) + { + for (i = 0; pkcs11_keys[i]; i++) + gnutls_free (pkcs11_keys[i]); + gnutls_free (pkcs11_keys); + } + rv = C_Finalize (NULL_PTR); if (rv != CKR_OK) { |