fix some more leaks, mostly suggestions from miod
authorjsg <jsg@openbsd.org>
Thu, 17 Apr 2014 18:38:53 +0000 (18:38 +0000)
committerjsg <jsg@openbsd.org>
Thu, 17 Apr 2014 18:38:53 +0000 (18:38 +0000)
ok miod@

12 files changed:
lib/libcrypto/asn1/asn_mime.c
lib/libcrypto/asn1/bio_asn1.c
lib/libcrypto/asn1/tasn_enc.c
lib/libcrypto/ocsp/ocsp_ht.c
lib/libcrypto/x509/x509_lu.c
lib/libcrypto/x509/x509spki.c
lib/libssl/src/crypto/asn1/asn_mime.c
lib/libssl/src/crypto/asn1/bio_asn1.c
lib/libssl/src/crypto/asn1/tasn_enc.c
lib/libssl/src/crypto/ocsp/ocsp_ht.c
lib/libssl/src/crypto/x509/x509_lu.c
lib/libssl/src/crypto/x509/x509spki.c

index 3de73fd..2b600ab 100644 (file)
@@ -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))) {
index fa98dba..b596459 100644 (file)
@@ -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;
index 9ab0473..54e3f7a 100644 (file)
@@ -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;
                        }
                }
index 0fa23b0..db20759 100644 (file)
@@ -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;
        }
index cbbe8e8..38b034b 100644 (file)
@@ -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;
        }
index 28bc12e..9f0fbd3 100644 (file)
@@ -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;
index 3de73fd..2b600ab 100644 (file)
@@ -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))) {
index fa98dba..b596459 100644 (file)
@@ -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;
index 9ab0473..54e3f7a 100644 (file)
@@ -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;
                        }
                }
index 0fa23b0..db20759 100644 (file)
@@ -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;
        }
index cbbe8e8..38b034b 100644 (file)
@@ -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;
        }
index 28bc12e..9f0fbd3 100644 (file)
@@ -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;