From 603b910f76de490c5cb41bc100b53945df7a8f65 Mon Sep 17 00:00:00 2001 From: jsg Date: Thu, 17 Apr 2014 18:38:53 +0000 Subject: [PATCH] fix some more leaks, mostly suggestions from miod ok miod@ --- lib/libcrypto/asn1/asn_mime.c | 4 +++- lib/libcrypto/asn1/bio_asn1.c | 4 +++- lib/libcrypto/asn1/tasn_enc.c | 2 ++ lib/libcrypto/ocsp/ocsp_ht.c | 3 +++ lib/libcrypto/x509/x509_lu.c | 1 + lib/libcrypto/x509/x509spki.c | 2 ++ lib/libssl/src/crypto/asn1/asn_mime.c | 4 +++- lib/libssl/src/crypto/asn1/bio_asn1.c | 4 +++- lib/libssl/src/crypto/asn1/tasn_enc.c | 2 ++ lib/libssl/src/crypto/ocsp/ocsp_ht.c | 3 +++ lib/libssl/src/crypto/x509/x509_lu.c | 1 + lib/libssl/src/crypto/x509/x509spki.c | 2 ++ 12 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/libcrypto/asn1/asn_mime.c b/lib/libcrypto/asn1/asn_mime.c index 3de73fdb1ef..2b600ab4112 100644 --- a/lib/libcrypto/asn1/asn_mime.c +++ b/lib/libcrypto/asn1/asn_mime.c @@ -823,8 +823,10 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) } } else tmpval = NULL; mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER)); - if (!mhdr) + if (!mhdr) { + OPENSSL_free(tmpname); return NULL; + } mhdr->name = tmpname; mhdr->value = tmpval; if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) { diff --git a/lib/libcrypto/asn1/bio_asn1.c b/lib/libcrypto/asn1/bio_asn1.c index fa98dba7283..b59645909cd 100644 --- a/lib/libcrypto/asn1/bio_asn1.c +++ b/lib/libcrypto/asn1/bio_asn1.c @@ -153,8 +153,10 @@ static int asn1_bio_new(BIO *b) ctx = malloc(sizeof(BIO_ASN1_BUF_CTX)); if (!ctx) return 0; - if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) + if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { + free(ctx); return 0; + } b->init = 1; b->ptr = (char *)ctx; b->flags = 0; diff --git a/lib/libcrypto/asn1/tasn_enc.c b/lib/libcrypto/asn1/tasn_enc.c index 9ab0473d73e..54e3f7a94a2 100644 --- a/lib/libcrypto/asn1/tasn_enc.c +++ b/lib/libcrypto/asn1/tasn_enc.c @@ -455,6 +455,8 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, * sizeof(*derlst)); tmpdat = malloc(skcontlen); if (!derlst || !tmpdat) + free(derlst); + free(tmpdat); return 0; } } diff --git a/lib/libcrypto/ocsp/ocsp_ht.c b/lib/libcrypto/ocsp/ocsp_ht.c index 0fa23b027b5..db20759d3ba 100644 --- a/lib/libcrypto/ocsp/ocsp_ht.c +++ b/lib/libcrypto/ocsp/ocsp_ht.c @@ -168,6 +168,7 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req, rctx->iobuflen = OCSP_MAX_LINE_LEN; rctx->iobuf = malloc(rctx->iobuflen); if (!rctx->iobuf) { + BIO_free(rctx->mem); free(rctx); return 0; } @@ -176,12 +177,14 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req, if (BIO_printf(rctx->mem, post_hdr, path) <= 0) { free(rctx->iobuf); + BIO_free(rctx->mem); free(rctx); return 0; } if (req && !OCSP_REQ_CTX_set1_req(rctx, req)) { free(rctx->iobuf); + BIO_free(rctx->mem); free(rctx); return 0; } diff --git a/lib/libcrypto/x509/x509_lu.c b/lib/libcrypto/x509/x509_lu.c index cbbe8e86f86..38b034bfeef 100644 --- a/lib/libcrypto/x509/x509_lu.c +++ b/lib/libcrypto/x509/x509_lu.c @@ -188,6 +188,7 @@ X509_STORE *X509_STORE_new(void) ret->verify_cb=0; if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) { + sk_X509_OBJECT_free(ret->objs); free(ret); return NULL; } diff --git a/lib/libcrypto/x509/x509spki.c b/lib/libcrypto/x509/x509spki.c index 28bc12e1a28..9f0fbd39e3e 100644 --- a/lib/libcrypto/x509/x509spki.c +++ b/lib/libcrypto/x509/x509spki.c @@ -111,6 +111,8 @@ char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) b64_str = malloc(der_len * 2); if(!der_spki || !b64_str) { X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); + free(der_spki); + free(b64_str); return NULL; } p = der_spki; diff --git a/lib/libssl/src/crypto/asn1/asn_mime.c b/lib/libssl/src/crypto/asn1/asn_mime.c index 3de73fdb1ef..2b600ab4112 100644 --- a/lib/libssl/src/crypto/asn1/asn_mime.c +++ b/lib/libssl/src/crypto/asn1/asn_mime.c @@ -823,8 +823,10 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) } } else tmpval = NULL; mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER)); - if (!mhdr) + if (!mhdr) { + OPENSSL_free(tmpname); return NULL; + } mhdr->name = tmpname; mhdr->value = tmpval; if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) { diff --git a/lib/libssl/src/crypto/asn1/bio_asn1.c b/lib/libssl/src/crypto/asn1/bio_asn1.c index fa98dba7283..b59645909cd 100644 --- a/lib/libssl/src/crypto/asn1/bio_asn1.c +++ b/lib/libssl/src/crypto/asn1/bio_asn1.c @@ -153,8 +153,10 @@ static int asn1_bio_new(BIO *b) ctx = malloc(sizeof(BIO_ASN1_BUF_CTX)); if (!ctx) return 0; - if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) + if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { + free(ctx); return 0; + } b->init = 1; b->ptr = (char *)ctx; b->flags = 0; diff --git a/lib/libssl/src/crypto/asn1/tasn_enc.c b/lib/libssl/src/crypto/asn1/tasn_enc.c index 9ab0473d73e..54e3f7a94a2 100644 --- a/lib/libssl/src/crypto/asn1/tasn_enc.c +++ b/lib/libssl/src/crypto/asn1/tasn_enc.c @@ -455,6 +455,8 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, * sizeof(*derlst)); tmpdat = malloc(skcontlen); if (!derlst || !tmpdat) + free(derlst); + free(tmpdat); return 0; } } diff --git a/lib/libssl/src/crypto/ocsp/ocsp_ht.c b/lib/libssl/src/crypto/ocsp/ocsp_ht.c index 0fa23b027b5..db20759d3ba 100644 --- a/lib/libssl/src/crypto/ocsp/ocsp_ht.c +++ b/lib/libssl/src/crypto/ocsp/ocsp_ht.c @@ -168,6 +168,7 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req, rctx->iobuflen = OCSP_MAX_LINE_LEN; rctx->iobuf = malloc(rctx->iobuflen); if (!rctx->iobuf) { + BIO_free(rctx->mem); free(rctx); return 0; } @@ -176,12 +177,14 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req, if (BIO_printf(rctx->mem, post_hdr, path) <= 0) { free(rctx->iobuf); + BIO_free(rctx->mem); free(rctx); return 0; } if (req && !OCSP_REQ_CTX_set1_req(rctx, req)) { free(rctx->iobuf); + BIO_free(rctx->mem); free(rctx); return 0; } diff --git a/lib/libssl/src/crypto/x509/x509_lu.c b/lib/libssl/src/crypto/x509/x509_lu.c index cbbe8e86f86..38b034bfeef 100644 --- a/lib/libssl/src/crypto/x509/x509_lu.c +++ b/lib/libssl/src/crypto/x509/x509_lu.c @@ -188,6 +188,7 @@ X509_STORE *X509_STORE_new(void) ret->verify_cb=0; if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) { + sk_X509_OBJECT_free(ret->objs); free(ret); return NULL; } diff --git a/lib/libssl/src/crypto/x509/x509spki.c b/lib/libssl/src/crypto/x509/x509spki.c index 28bc12e1a28..9f0fbd39e3e 100644 --- a/lib/libssl/src/crypto/x509/x509spki.c +++ b/lib/libssl/src/crypto/x509/x509spki.c @@ -111,6 +111,8 @@ char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) b64_str = malloc(der_len * 2); if(!der_spki || !b64_str) { X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); + free(der_spki); + free(b64_str); return NULL; } p = der_spki; -- 2.20.1