Skip to content

Commit 90a2c79

Browse files
committed
Remove some unnnecessary null checks in openssl
Remove null checks before EVP_PKEY_free and BIO_free. NULL is a no-op for both of these. Probably applies to most other freeing function as well...
1 parent 80d3ce3 commit 90a2c79

File tree

1 file changed

+22
-69
lines changed

1 file changed

+22
-69
lines changed

ext/openssl/openssl.c

Lines changed: 22 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,9 +1612,7 @@ PHP_FUNCTION(openssl_spki_new)
16121612
goto cleanup;
16131613

16141614
cleanup:
1615-
if (pkey != NULL) {
1616-
EVP_PKEY_free(pkey);
1617-
}
1615+
EVP_PKEY_free(pkey);
16181616
if (spki != NULL) {
16191617
NETSCAPE_SPKI_free(spki);
16201618
}
@@ -1669,9 +1667,7 @@ PHP_FUNCTION(openssl_spki_verify)
16691667
if (spki != NULL) {
16701668
NETSCAPE_SPKI_free(spki);
16711669
}
1672-
if (pkey != NULL) {
1673-
EVP_PKEY_free(pkey);
1674-
}
1670+
EVP_PKEY_free(pkey);
16751671
if (spkstr_cleaned != NULL) {
16761672
efree(spkstr_cleaned);
16771673
}
@@ -1738,12 +1734,8 @@ PHP_FUNCTION(openssl_spki_export)
17381734
if (spki != NULL) {
17391735
NETSCAPE_SPKI_free(spki);
17401736
}
1741-
if (out != NULL) {
1742-
BIO_free_all(out);
1743-
}
1744-
if (pkey != NULL) {
1745-
EVP_PKEY_free(pkey);
1746-
}
1737+
BIO_free_all(out);
1738+
EVP_PKEY_free(pkey);
17471739
if (spkstr_cleaned != NULL) {
17481740
efree(spkstr_cleaned);
17491741
}
@@ -2627,10 +2619,7 @@ PHP_FUNCTION(openssl_pkcs12_export_to_file)
26272619
php_sk_X509_free(ca);
26282620

26292621
cleanup:
2630-
2631-
if (priv_key) {
2632-
EVP_PKEY_free(priv_key);
2633-
}
2622+
EVP_PKEY_free(priv_key);
26342623

26352624
if (cert_str) {
26362625
X509_free(cert);
@@ -2719,10 +2708,7 @@ PHP_FUNCTION(openssl_pkcs12_export)
27192708
php_sk_X509_free(ca);
27202709

27212710
cleanup:
2722-
2723-
if (priv_key) {
2724-
EVP_PKEY_free(priv_key);
2725-
}
2711+
EVP_PKEY_free(priv_key);
27262712
if (cert_str) {
27272713
X509_free(cert);
27282714
}
@@ -2822,13 +2808,9 @@ PHP_FUNCTION(openssl_pkcs12_read)
28222808
php_openssl_store_errors();
28232809
}
28242810

2825-
cleanup:
2826-
if (bio_in) {
2827-
BIO_free(bio_in);
2828-
}
2829-
if (pkey) {
2830-
EVP_PKEY_free(pkey);
2831-
}
2811+
cleanup:
2812+
BIO_free(bio_in);
2813+
EVP_PKEY_free(pkey);
28322814
if (cert) {
28332815
X509_free(cert);
28342816
}
@@ -3300,13 +3282,8 @@ PHP_FUNCTION(openssl_csr_sign)
33003282
}
33013283

33023284
PHP_SSL_REQ_DISPOSE(&req);
3303-
3304-
if (priv_key) {
3305-
EVP_PKEY_free(priv_key);
3306-
}
3307-
if (key) {
3308-
EVP_PKEY_free(key);
3309-
}
3285+
EVP_PKEY_free(priv_key);
3286+
EVP_PKEY_free(key);
33103287
if (csr_str) {
33113288
X509_REQ_free(csr);
33123289
}
@@ -4265,9 +4242,7 @@ PHP_FUNCTION(openssl_pkey_new)
42654242
if (eckey != NULL) {
42664243
EC_KEY_free(eckey);
42674244
}
4268-
if (pkey != NULL) {
4269-
EVP_PKEY_free(pkey);
4270-
}
4245+
EVP_PKEY_free(pkey);
42714246
RETURN_FALSE;
42724247
#endif
42734248
}
@@ -4367,13 +4342,8 @@ PHP_FUNCTION(openssl_pkey_export_to_file)
43674342

43684343
clean_exit:
43694344
PHP_SSL_REQ_DISPOSE(&req);
4370-
4371-
if (key) {
4372-
EVP_PKEY_free(key);
4373-
}
4374-
if (bio_out) {
4375-
BIO_free(bio_out);
4376-
}
4345+
EVP_PKEY_free(key);
4346+
BIO_free(bio_out);
43774347
}
43784348
/* }}} */
43794349

@@ -4448,13 +4418,8 @@ PHP_FUNCTION(openssl_pkey_export)
44484418
}
44494419
}
44504420
PHP_SSL_REQ_DISPOSE(&req);
4451-
4452-
if (key) {
4453-
EVP_PKEY_free(key);
4454-
}
4455-
if (bio_out) {
4456-
BIO_free(bio_out);
4457-
}
4421+
EVP_PKEY_free(key);
4422+
BIO_free(bio_out);
44584423
}
44594424
/* }}} */
44604425

@@ -4789,12 +4754,8 @@ PHP_FUNCTION(openssl_pkey_derive)
47894754
}
47904755

47914756
cleanup:
4792-
if (pkey) {
4793-
EVP_PKEY_free(pkey);
4794-
}
4795-
if (peer_key) {
4796-
EVP_PKEY_free(peer_key);
4797-
}
4757+
EVP_PKEY_free(pkey);
4758+
EVP_PKEY_free(peer_key);
47984759
if (ctx) {
47994760
EVP_PKEY_CTX_free(ctx);
48004761
}
@@ -5231,9 +5192,7 @@ PHP_FUNCTION(openssl_pkcs7_read)
52315192
RETVAL_TRUE;
52325193

52335194
clean_exit:
5234-
if (bio_in != NULL) {
5235-
BIO_free(bio_in);
5236-
}
5195+
BIO_free(bio_in);
52375196

52385197
if (p7 != NULL) {
52395198
PKCS7_free(p7);
@@ -5359,9 +5318,7 @@ PHP_FUNCTION(openssl_pkcs7_sign)
53595318
if (others) {
53605319
sk_X509_pop_free(others, X509_free);
53615320
}
5362-
if (privkey) {
5363-
EVP_PKEY_free(privkey);
5364-
}
5321+
EVP_PKEY_free(privkey);
53655322
if (cert && cert_str) {
53665323
X509_free(cert);
53675324
}
@@ -5441,9 +5398,7 @@ PHP_FUNCTION(openssl_pkcs7_decrypt)
54415398
if (cert && free_recipcert) {
54425399
X509_free(cert);
54435400
}
5444-
if (key) {
5445-
EVP_PKEY_free(key);
5446-
}
5401+
EVP_PKEY_free(key);
54475402
}
54485403
/* }}} */
54495404

@@ -6191,9 +6146,7 @@ PHP_FUNCTION(openssl_cms_decrypt)
61916146
if (cert && free_recipcert) {
61926147
X509_free(cert);
61936148
}
6194-
if (key) {
6195-
EVP_PKEY_free(key);
6196-
}
6149+
EVP_PKEY_free(key);
61976150
}
61986151
/* }}} */
61996152

0 commit comments

Comments
 (0)