fix some of the leaks
authorjsg <jsg@openbsd.org>
Thu, 17 Apr 2014 17:30:22 +0000 (17:30 +0000)
committerjsg <jsg@openbsd.org>
Thu, 17 Apr 2014 17:30:22 +0000 (17:30 +0000)
ok miod@ looks good deraadt@

lib/libcrypto/asn1/asn_mime.c
lib/libcrypto/ocsp/ocsp_ht.c
lib/libcrypto/pem/pvkfmt.c
lib/libcrypto/x509/x509_lu.c
lib/libssl/src/crypto/asn1/asn_mime.c
lib/libssl/src/crypto/ocsp/ocsp_ht.c
lib/libssl/src/crypto/pem/pvkfmt.c
lib/libssl/src/crypto/x509/x509_lu.c

index d94b3cd..3de73fd 100644 (file)
@@ -823,10 +823,14 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
                }
        } else tmpval = NULL;
        mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER));
-       if(!mhdr) return NULL;
+       if (!mhdr)
+               return NULL;
        mhdr->name = tmpname;
        mhdr->value = tmpval;
-       if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL;
+       if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) {
+               free(mhdr);
+               return NULL;
+       }
        return mhdr;
 }
                
index 17b252d..0fa23b0 100644 (file)
@@ -167,16 +167,24 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
        else
                rctx->iobuflen = OCSP_MAX_LINE_LEN;
        rctx->iobuf = malloc(rctx->iobuflen);
-       if (!rctx->iobuf)
+       if (!rctx->iobuf) {
+               free(rctx);
                return 0;
+       }
        if (!path)
                path = "/";
 
-        if (BIO_printf(rctx->mem, post_hdr, path) <= 0)
+        if (BIO_printf(rctx->mem, post_hdr, path) <= 0) {
+               free(rctx->iobuf);
+               free(rctx);
                return 0;
+       }
 
-       if (req && !OCSP_REQ_CTX_set1_req(rctx, req))
+       if (req && !OCSP_REQ_CTX_set1_req(rctx, req)) {
+               free(rctx->iobuf);
+               free(rctx);
                return 0;
+       }
 
        return rctx;
        }
index 8da8e77..59af202 100644 (file)
@@ -753,8 +753,10 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
                        return NULL;
                        }
                if (!derive_pvk_key(keybuf, p, saltlen,
-                           (unsigned char *)psbuf, inlen))
+                           (unsigned char *)psbuf, inlen)) {
+                       free(enctmp);
                        return NULL;
+               }
                p += saltlen;
                /* Copy BLOBHEADER across, decrypt rest */
                memcpy(enctmp, p, 8);
index 644ea83..cbbe8e8 100644 (file)
@@ -187,8 +187,10 @@ X509_STORE *X509_STORE_new(void)
        ret->verify=0;
        ret->verify_cb=0;
 
-       if ((ret->param = X509_VERIFY_PARAM_new()) == NULL)
+       if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) {
+               free(ret);
                return NULL;
+       }
 
        ret->get_issuer = 0;
        ret->check_issued = 0;
index d94b3cd..3de73fd 100644 (file)
@@ -823,10 +823,14 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
                }
        } else tmpval = NULL;
        mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER));
-       if(!mhdr) return NULL;
+       if (!mhdr)
+               return NULL;
        mhdr->name = tmpname;
        mhdr->value = tmpval;
-       if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL;
+       if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) {
+               free(mhdr);
+               return NULL;
+       }
        return mhdr;
 }
                
index 17b252d..0fa23b0 100644 (file)
@@ -167,16 +167,24 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
        else
                rctx->iobuflen = OCSP_MAX_LINE_LEN;
        rctx->iobuf = malloc(rctx->iobuflen);
-       if (!rctx->iobuf)
+       if (!rctx->iobuf) {
+               free(rctx);
                return 0;
+       }
        if (!path)
                path = "/";
 
-        if (BIO_printf(rctx->mem, post_hdr, path) <= 0)
+        if (BIO_printf(rctx->mem, post_hdr, path) <= 0) {
+               free(rctx->iobuf);
+               free(rctx);
                return 0;
+       }
 
-       if (req && !OCSP_REQ_CTX_set1_req(rctx, req))
+       if (req && !OCSP_REQ_CTX_set1_req(rctx, req)) {
+               free(rctx->iobuf);
+               free(rctx);
                return 0;
+       }
 
        return rctx;
        }
index 8da8e77..59af202 100644 (file)
@@ -753,8 +753,10 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
                        return NULL;
                        }
                if (!derive_pvk_key(keybuf, p, saltlen,
-                           (unsigned char *)psbuf, inlen))
+                           (unsigned char *)psbuf, inlen)) {
+                       free(enctmp);
                        return NULL;
+               }
                p += saltlen;
                /* Copy BLOBHEADER across, decrypt rest */
                memcpy(enctmp, p, 8);
index 644ea83..cbbe8e8 100644 (file)
@@ -187,8 +187,10 @@ X509_STORE *X509_STORE_new(void)
        ret->verify=0;
        ret->verify_cb=0;
 
-       if ((ret->param = X509_VERIFY_PARAM_new()) == NULL)
+       if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) {
+               free(ret);
                return NULL;
+       }
 
        ret->get_issuer = 0;
        ret->check_issued = 0;