From: Pauli Date: Fri, 25 Jun 2021 02:57:37 +0000 (+1000) Subject: test: avoid memory leaks on errors X-Git-Tag: openssl-3.0.0-beta2~184 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=711d5a2fc0d611d5574c6d81b9cc0aa1564d2d2a;p=thirdparty%2Fopenssl.git test: avoid memory leaks on errors Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/15910) --- diff --git a/test/conf_include_test.c b/test/conf_include_test.c index 1c00c601e59..2481a2380b7 100644 --- a/test/conf_include_test.c +++ b/test/conf_include_test.c @@ -42,7 +42,7 @@ static int change_path(const char *file) char *s = OPENSSL_strdup(file); char *p = s; char *last = NULL; - int ret; + int ret = 0; if (s == NULL) return -1; @@ -51,11 +51,12 @@ static int change_path(const char *file) last = p++; } if (last == NULL) - return 0; + goto err; last[DIRSEP_PRESERVE] = 0; TEST_note("changing path to %s", s); ret = chdir(s); + err: OPENSSL_free(s); return ret; } diff --git a/test/helpers/handshake.c b/test/helpers/handshake.c index 0543634c73d..d44aa4baafe 100644 --- a/test/helpers/handshake.c +++ b/test/helpers/handshake.c @@ -278,8 +278,10 @@ static int server_ocsp_cb(SSL *s, void *arg) * For the purposes of testing we just send back a dummy OCSP response */ *resp = *(unsigned char *)arg; - if (!SSL_set_tlsext_status_ocsp_resp(s, resp, 1)) + if (!SSL_set_tlsext_status_ocsp_resp(s, resp, 1)) { + OPENSSL_free(resp); return SSL_TLSEXT_ERR_ALERT_FATAL; + } return SSL_TLSEXT_ERR_OK; } diff --git a/test/sslapitest.c b/test/sslapitest.c index 850c941ac24..bbb1cf91f40 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -1644,7 +1644,11 @@ static int ocsp_server_cb(SSL *s, void *arg) if (!TEST_ptr(copy = OPENSSL_memdup(orespder, sizeof(orespder)))) return SSL_TLSEXT_ERR_ALERT_FATAL; - SSL_set_tlsext_status_ocsp_resp(s, copy, sizeof(orespder)); + if (!TEST_true(SSL_set_tlsext_status_ocsp_resp(s, copy, + sizeof(orespder)))) { + OPENSSL_free(copy); + return SSL_TLSEXT_ERR_ALERT_FATAL; + } ocsp_server_called = 1; return SSL_TLSEXT_ERR_OK; }