diff options
author | Linus Nordberg <linus@nordu.net> | 2016-09-21 12:53:31 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2016-09-21 13:04:24 +0200 |
commit | e12e83b6f905fe6d27371921c36c5c3dad9e5379 (patch) | |
tree | 6360a09ea85ca4197d1677ff05d86d053cfbdf72 /tls.c | |
parent | 5acfcb4c7ce94482660dedb710e0b1f2ab8e5578 (diff) |
Don't cast int to pointer and back. Portability.stompless-rebased
Thanks to Fabian Mauchle for pointing this out.
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 |