diff options
author | Matt Caswell <matt@openssl.org> | 2016-04-28 13:53:52 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-06-01 18:00:53 +0100 |
commit | 137e5555bd3d1dc4486619bc524502c55682a6f4 (patch) | |
tree | bac8744afa70a61c4b9880fa742c7c7d14a7742c /crypto/x509v3/v3_purp.c | |
parent | 423281001ce96d731361152f8f6c52a1fefc2660 (diff) | |
download | openssl-137e5555bd3d1dc4486619bc524502c55682a6f4.zip openssl-137e5555bd3d1dc4486619bc524502c55682a6f4.tar.gz openssl-137e5555bd3d1dc4486619bc524502c55682a6f4.tar.bz2 |
Don't leak memory on int X509_PURPOSE_add() error path
The int X509_PURPOSE_add() function was leaking an X509_PURPOSE object
on error.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/x509v3/v3_purp.c')
-rw-r--r-- | crypto/x509v3/v3_purp.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index b757d8e..b0d40ed 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -180,7 +180,7 @@ int X509_PURPOSE_add(int id, int trust, int flags, ptmp->sname = OPENSSL_strdup(sname); if (!ptmp->name || !ptmp->sname) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); - return 0; + goto err; } /* Keep the dynamic flag of existing entry */ ptmp->flags &= X509_PURPOSE_DYNAMIC; @@ -197,14 +197,21 @@ int X509_PURPOSE_add(int id, int trust, int flags, if (xptable == NULL && (xptable = sk_X509_PURPOSE_new(xp_cmp)) == NULL) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); - return 0; + goto err; } if (!sk_X509_PURPOSE_push(xptable, ptmp)) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); - return 0; + goto err; } } return 1; + err: + if (idx == -1) { + OPENSSL_free(ptmp->name); + OPENSSL_free(ptmp->sname); + OPENSSL_free(ptmp); + } + return 0; } static void xptable_free(X509_PURPOSE *p) |