From 470ac87f7367228dee6a94b921ac4eb082234dee Mon Sep 17 00:00:00 2001 From: Sven Geuer <68420948@users.noreply.github.com> Date: Sat, 2 Dec 2023 19:37:56 +0100 Subject: [PATCH] Use alloca() instead of malloc() This make code more readable and spares us some explicit calls to free(). --- ptstream.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ptstream.c b/ptstream.c index 0ba3bf4..6131fa4 100644 --- a/ptstream.c +++ b/ptstream.c @@ -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); }