Commit 222561fe authored by Rich Salz's avatar Rich Salz
Browse files

free NULL cleanup 5a



Don't check for NULL before calling a free routine.  This gets X509_.*free:
    x509_name_ex_free X509_policy_tree_free X509_VERIFY_PARAM_free
    X509_STORE_free X509_STORE_CTX_free X509_PKEY_free
    X509_OBJECT_free_contents X509_LOOKUP_free X509_INFO_free

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent 2ace7450
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -971,7 +971,6 @@ static int load_certs_crls(const char *file, int format,

 end:

    if (xis)
    sk_X509_INFO_pop_free(xis, X509_INFO_free);

    if (rv == 0) {
+15 −29
Original line number Diff line number Diff line
@@ -1349,8 +1349,6 @@ end_of_options:
    BIO_free_all(Sout);
    BIO_free_all(out);
    BIO_free_all(in);

    if (cert_sk)
    sk_X509_pop_free(cert_sk, X509_free);

    if (ret)
@@ -1364,7 +1362,6 @@ end_of_options:
    if (sigopts)
        sk_OPENSSL_STRING_free(sigopts);
    EVP_PKEY_free(pkey);
    if (x509)
    X509_free(x509);
    X509_CRL_free(crl);
    NCONF_free(conf);
@@ -1440,7 +1437,6 @@ static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
                 ext_copy, selfsign);

 end:
    if (req != NULL)
    X509_REQ_free(req);
    BIO_free(in);
    return (ok);
@@ -1495,9 +1491,7 @@ static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
                 ext_copy, 0);

 end:
    if (rreq != NULL)
    X509_REQ_free(rreq);
    if (req != NULL)
    X509_free(req);
    return (ok);
}
@@ -1700,7 +1694,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,

            if (push != NULL) {
                if (!X509_NAME_add_entry(subject, push, -1, 0)) {
                    if (push != NULL)
                    X509_NAME_ENTRY_free(push);
                    BIO_printf(bio_err, "Memory allocation failure\n");
                    goto end;
@@ -1876,7 +1869,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
        /*
         * Free the current entries if any, there should not be any I believe
         */
        if (ci->extensions != NULL)
        sk_X509_EXTENSION_pop_free(ci->extensions, X509_EXTENSION_free);

        ci->extensions = NULL;
@@ -2027,18 +2019,14 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
        if (row[i] != NULL)
            OPENSSL_free(row[i]);

    if (CAname != NULL)
    X509_NAME_free(CAname);
    if (subject != NULL)
    X509_NAME_free(subject);
    if ((dn_subject != NULL) && !email_dn)
    if (dn_subject != subject)
        X509_NAME_free(dn_subject);
    ASN1_UTCTIME_free(tmptm);
    if (ok <= 0) {
        if (ret != NULL)
    if (ok <= 0)
        X509_free(ret);
        ret = NULL;
    } else
    else
        *xret = ret;
    return (ok);
}
@@ -2186,13 +2174,11 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey,
                 verbose, req, ext_sect, lconf, certopt, nameopt, default_op,
                 ext_copy, 0);
 end:
    if (req != NULL)
    X509_REQ_free(req);
    if (parms != NULL)
        CONF_free(parms);
    if (spki != NULL)
        NETSCAPE_SPKI_free(spki);
    if (ne != NULL)
    X509_NAME_ENTRY_free(ne);

    return (ok);
+2 −4
Original line number Diff line number Diff line
@@ -215,7 +215,6 @@ int crl2pkcs7_main(int argc, char **argv)
    BIO_free(in);
    BIO_free_all(out);
    PKCS7_free(p7);
    if (crl != NULL)
    X509_CRL_free(crl);

    return (ret);
@@ -267,7 +266,6 @@ static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile)
 end:
    /* never need to OPENSSL_free x */
    BIO_free(in);
    if (sk != NULL)
    sk_X509_INFO_free(sk);
    return (ret);
}
+1 −2
Original line number Diff line number Diff line
@@ -735,7 +735,6 @@ int ocsp_main(int argc, char **argv)
    ERR_print_errors(bio_err);
    X509_free(signer);
    X509_STORE_free(store);
    if (vpm)
    X509_VERIFY_PARAM_free(vpm);
    EVP_PKEY_free(key);
    EVP_PKEY_free(rkey);
+2 −4
Original line number Diff line number Diff line
@@ -504,9 +504,7 @@ int pkcs12_main(int argc, char **argv)
 export_end:

        EVP_PKEY_free(key);
        if (certs)
        sk_X509_pop_free(certs, X509_free);
        if (ucert)
        X509_free(ucert);

        goto end;
Loading