Skip to content

Commit

Permalink
Added error checking in PKCS11_CTX_new()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos Mavrogiannopoulos committed Jul 13, 2015
1 parent fe211c1 commit e5aa18c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/p11_load.c
Expand Up @@ -27,22 +27,32 @@ static void *handle = NULL;
*/
PKCS11_CTX *PKCS11_CTX_new(void)
{
PKCS11_CTX_private *priv;
PKCS11_CTX *ctx;
PKCS11_CTX_private *priv = NULL;
PKCS11_CTX *ctx = NULL;

/* Load error strings */
ERR_load_PKCS11_strings();

priv = PKCS11_NEW(PKCS11_CTX_private);
if (priv == NULL)
goto fail;
ctx = PKCS11_NEW(PKCS11_CTX);
if (ctx == NULL)
goto fail;
ctx->_private = priv;
priv->forkid = _P11_get_forkid();

#ifndef _WIN32
pthread_mutex_init(&priv->mutex, NULL);
if (pthread_mutex_init(&priv->mutex, NULL) != 0) {
goto fail;
}
#endif

return ctx;
fail:
OPENSSL_free(priv);
OPENSSL_free(ctx);
return NULL;
}

/*
Expand Down

0 comments on commit e5aa18c

Please sign in to comment.