From 71a1cfdf066012ea4a8c8049cb3dc3554348d2b2 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 18 Apr 2016 15:02:38 +0200 Subject: Stomp less on other threads memory. See RADSECPROXY-64. --- tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index 11bad5e..e903cc5 100644 --- a/tcp.c +++ b/tcp.c @@ -317,6 +317,7 @@ void *tcpservernew(void *arg) { struct client *client; s = *(int *)arg; + free(arg); if (getpeername(s, (struct sockaddr *)&from, &fromlen)) { debug(DBG_DBG, "tcpservernew: getpeername failed, exiting"); goto exit; @@ -344,7 +345,7 @@ exit: void *tcplistener(void *arg) { pthread_t tcpserverth; - int s, *sp = (int *)arg; + int s, *sp = (int *)arg, *s_arg = NULL; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); @@ -356,8 +357,13 @@ void *tcplistener(void *arg) { debug(DBG_WARN, "accept failed"); continue; } - if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *)&s)) { + s_arg = malloc(sizeof(s)); + if (!s_arg) + debugx(1, DBG_ERR, "malloc failed"); + *s_arg = s; + if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *) s_arg)) { debug(DBG_ERR, "tcplistener: pthread_create failed"); + free(s_arg); shutdown(s, SHUT_RDWR); close(s); continue; -- cgit v1.1