diff options
author | Matt Caswell <matt@openssl.org> | 2016-04-28 13:46:31 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-06-01 18:00:53 +0100 |
commit | 423281001ce96d731361152f8f6c52a1fefc2660 (patch) | |
tree | b86ec594deafc28ccbc47affb3279ce53e54e7ed /crypto/x509/x509_trs.c | |
parent | 69e2bd32efb756b59cea75af22d869679c448e91 (diff) |
Don't leak memory on X509_TRUST_add() error path
The X509_TRUST_add() function was leaking an X509_TRUST object on error.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/x509/x509_trs.c')
-rw-r--r-- | crypto/x509/x509_trs.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crypto/x509/x509_trs.c b/crypto/x509/x509_trs.c index db0024f2db..d736418cbe 100644 --- a/crypto/x509/x509_trs.c +++ b/crypto/x509/x509_trs.c @@ -148,7 +148,7 @@ int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), /* dup supplied name */ if ((trtmp->name = OPENSSL_strdup(name)) == NULL) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); - return 0; + goto err; } /* Keep the dynamic flag of existing entry */ trtmp->flags &= X509_TRUST_DYNAMIC; @@ -165,14 +165,20 @@ int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), if (trtable == NULL && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); - return 0; + goto err;; } if (!sk_X509_TRUST_push(trtable, trtmp)) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); - return 0; + goto err; } } return 1; + err: + if (idx == -1) { + OPENSSL_free(trtmp->name); + OPENSSL_free(trtmp); + } + return 0; } static void trtable_free(X509_TRUST *p) |