From f19dfac830a728f4d77e7e4d1aae3eb05c9496ac Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 6 Jun 2017 16:45:39 +0200 Subject: openssl: Fix spkstr and spki leak in openssl_spki_new spkstr is not free'd when running the test and valgrind reports a leak of 32,318 bytes. The free condition is not met since keyresource is not NULL, apart from that OPENSSL_free actually free's the allocated memory by OPENSSL_malloc inside OpenSSL. Valgrind reports 768 bytes leaked in openssl_spki_new when running the testsuite. Remove the keyresource check to always free spki. --- ext/openssl/openssl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ext/openssl') diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 6b382ba6bd..6203267a05 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -1760,21 +1760,19 @@ PHP_FUNCTION(openssl_spki_new) s = zend_string_alloc(strlen(spkac) + strlen(spkstr), 0); sprintf(ZSTR_VAL(s), "%s%s", spkac, spkstr); ZSTR_LEN(s) = strlen(ZSTR_VAL(s)); + OPENSSL_free(spkstr); RETVAL_STR(s); goto cleanup; cleanup: - if (keyresource == NULL && spki != NULL) { + if (spki != NULL) { NETSCAPE_SPKI_free(spki); } if (keyresource == NULL && pkey != NULL) { EVP_PKEY_free(pkey); } - if (keyresource == NULL && spkstr != NULL) { - efree(spkstr); - } if (s && ZSTR_LEN(s) <= 0) { RETVAL_FALSE; -- cgit v1.2.1