test: avoid memory leaks on errors

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/15910)
This commit is contained in:
Pauli 2021-06-25 12:57:37 +10:00
parent 1f25fd1616
commit 711d5a2fc0
3 changed files with 11 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}