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:12:54 +0200 |
commit | c928c63f85a91305a063e1dfe705d86d30f35dbf (patch) | |
tree | 7ca02a19f836290aef9050e30658bedcf3309ecf /tls.c | |
parent | 46e97b761ccf654120e65f394317adbe49720bcf (diff) |
Stomp less on other threads memory.
See RADSECPROXY-64.
Diffstat (limited to 'tls.c')
-rw-r--r-- | tls.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -402,6 +402,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; @@ -462,7 +463,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); @@ -474,8 +475,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; |