diff options
author | Linus Nordberg <linus@nordu.net> | 2016-04-18 15:02:38 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2016-09-21 13:06:46 +0200 |
commit | 71a1cfdf066012ea4a8c8049cb3dc3554348d2b2 (patch) | |
tree | 6360a09ea85ca4197d1677ff05d86d053cfbdf72 | |
parent | 6c1f37d727afb31ac3fa4af4a4158993897d402d (diff) |
Stomp less on other threads memory.stompless-rebased-squashed
See RADSECPROXY-64.
-rw-r--r-- | tcp.c | 10 | ||||
-rw-r--r-- | tls.c | 10 |
2 files changed, 16 insertions, 4 deletions
@@ -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; @@ -398,6 +398,7 @@ void *tlsservernew(void *arg) { struct tls *accepted_tls = NULL; s = *(int *)arg; + free(arg); if (getpeername(s, (struct sockaddr *)&from, &fromlen)) { debug(DBG_DBG, "tlsservernew: getpeername failed, exiting"); goto exit; @@ -458,7 +459,7 @@ exit: void *tlslistener(void *arg) { pthread_t tlsserverth; - int s, *sp = (int *)arg; + int s, *sp = (int *)arg, *s_arg = NULL; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); @@ -470,8 +471,13 @@ void *tlslistener(void *arg) { debug(DBG_WARN, "accept failed"); continue; } - if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *)&s)) { + s_arg = malloc(sizeof(s)); + if (!s_arg) + debugx(1, DBG_ERR, "malloc failed"); + *s_arg = s; + if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *) s_arg)) { debug(DBG_ERR, "tlslistener: pthread_create failed"); + free(s_arg); shutdown(s, SHUT_RDWR); close(s); continue; |