Use alloca() instead of malloc()

This make code more readable and spares us some explicit calls to
free().
This commit is contained in:
Sven Geuer 2023-12-02 19:37:56 +01:00
parent 8d69435854
commit 470ac87f73

View file

@ -327,10 +327,7 @@ int stream_enable_ssl(PTSTREAM *pts, const char *proxy_arg) {
/* Determine the host name we are connecting to */
proxy_arg_len = strlen(proxy_arg);
if ((peer_host = malloc(proxy_arg_len + 1)) == NULL) {
message("Out of memory\n");
goto fail;
}
peer_host = alloca(proxy_arg_len + 1);
snprintf( proxy_arg_fmt, sizeof(proxy_arg_fmt), proxy_arg[0] == '[' ? "[%%%zu[^]]]" : "%%%zu[^:]", proxy_arg_len - 1 );
if ( sscanf( proxy_arg, proxy_arg_fmt, peer_host ) != 1 ) {
goto fail;
@ -373,7 +370,6 @@ int stream_enable_ssl(PTSTREAM *pts, const char *proxy_arg) {
goto fail;
}
free(peer_host);
X509_free(cert);
}
@ -391,9 +387,6 @@ fail:
if (cert != NULL) {
X509_free(cert);
}
if (peer_host != NULL) {
free(peer_host);
}
#endif /* USE_SSL */
exit(1);
}