From e12e83b6f905fe6d27371921c36c5c3dad9e5379 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 21 Sep 2016 12:53:31 +0200 Subject: Don't cast int to pointer and back. Portability. Thanks to Fabian Mauchle for pointing this out. --- tls.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'tls.c') diff --git a/tls.c b/tls.c index 0564c7e..38f3bb3 100644 --- a/tls.c +++ b/tls.c @@ -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 -- cgit v1.1