diff options
Diffstat (limited to 'tls.c')
-rw-r--r-- | tls.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -397,7 +397,8 @@ void *tlsservernew(void *arg) { struct client *client; struct tls *accepted_tls = NULL; - s = (int) arg; + s = *(int *)arg; + free(arg); if (getpeername(s, (struct sockaddr *)&from, &fromlen)) { debug(DBG_DBG, "tlsservernew: getpeername failed, exiting"); goto exit; @@ -458,26 +459,32 @@ exit: void *tlslistener(void *arg) { pthread_t tlsserverth; - int s, listensock = (int) arg; + int s, *sp = (int *)arg, *s_arg = NULL; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); - listen(listensock, 0); + listen(*sp, 0); for (;;) { - s = accept(listensock, (struct sockaddr *)&from, &fromlen); + s = accept(*sp, (struct sockaddr *)&from, &fromlen); if (s < 0) { 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; } pthread_detach(tlsserverth); } + free(sp); return NULL; } #else |