[pkg-opensc-commit] [libp11] 210/239: Fix two memory leaks with init_args

Eric Dorland eric at moszumanska.debian.org
Sat Oct 17 06:21:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository libp11.

commit 56ca6a7a2fb92b204551902ee8b5305627a3238b
Author: Christian Heimes <christian at python.org>
Date:   Mon Jun 8 09:34:53 2015 +0200

    Fix two memory leaks with init_args
    
    PKCS11_CTX_init_args() duplicates init_args string with strdup(). The
    result must be freed with free() eventually. PKCS11_CTX_init_args()
    now calls free() on the previously allocated string and PKCS11_CTX_free()
    frees priv->init_args, too.
---
 src/p11_load.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/p11_load.c b/src/p11_load.c
index d94dc03..a93378c 100644
--- a/src/p11_load.c
+++ b/src/p11_load.c
@@ -55,6 +55,10 @@ PKCS11_CTX *PKCS11_CTX_new(void)
 void PKCS11_CTX_init_args(PKCS11_CTX * ctx, const char *init_args)
 {
 	PKCS11_CTX_private *priv = PRIVCTX(ctx);
+	/* Free previously duplicated string */
+	if (priv->init_args) {
+		free(priv->init_args);
+	}
 	priv->init_args = init_args ? strdup(init_args) : NULL;
 }
 
@@ -150,12 +154,16 @@ void PKCS11_CTX_unload(PKCS11_CTX * ctx)
  */
 void PKCS11_CTX_free(PKCS11_CTX * ctx)
 {
+	PKCS11_CTX_private *priv = PRIVCTX(ctx);
 	/* Do not remove the strings since OpenSSL strings may still be used by
 	 * the application and we can't know
 
 	ERR_free_strings();
 	ERR_remove_state(0);
 	*/
+	if (priv->init_args) {
+		free(priv->init_args);
+	}
 	OPENSSL_free(ctx->manufacturer);
 	OPENSSL_free(ctx->description);
 	OPENSSL_free(ctx->_private);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git



More information about the pkg-opensc-commit mailing list