From 5acfcb4c7ce94482660dedb710e0b1f2ab8e5578 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 18 Apr 2016 15:02:38 +0200 Subject: Stomp less on other threads memory. See RADSECPROXY-64. --- radsecproxy.c | 10 ++-------- tcp.c | 9 ++++----- tls.c | 11 +++++------ udp.c | 8 ++++---- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/radsecproxy.c b/radsecproxy.c index 1590e65..d4b6578 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -1990,7 +1990,7 @@ errexit: void createlistener(uint8_t type, char *arg) { pthread_t th; struct addrinfo *res; - int s = -1, on = 1, *sp = NULL; + int s = -1, on = 1; struct hostportres *hp = newhostport(arg, protodefs[type]->portdefault, 0); if (!hp || !resolvehostport(hp, AF_UNSPEC, protodefs[type]->socktype, 1)) @@ -2017,16 +2017,10 @@ void createlistener(uint8_t type, char *arg) { continue; } - sp = malloc(sizeof(int)); - if (!sp) - debugx(1, DBG_ERR, "malloc failed"); - *sp = s; - if (pthread_create(&th, &pthread_attr, protodefs[type]->listener, (void *)sp)) + if (pthread_create(&th, &pthread_attr, protodefs[type]->listener, (void *)s)) debugerrnox(errno, DBG_ERR, "pthread_create failed"); pthread_detach(th); } - if (!sp) - debugx(1, DBG_ERR, "createlistener: socket/bind failed"); debug(DBG_WARN, "createlistener: listening for %s on %s:%s", protodefs[type]->name, hp->host ? hp->host : "*", hp->port); freehostport(hp); diff --git a/tcp.c b/tcp.c index 11bad5e..6870a9c 100644 --- a/tcp.c +++ b/tcp.c @@ -344,19 +344,19 @@ exit: void *tcplistener(void *arg) { pthread_t tcpserverth; - int s, *sp = (int *)arg; + int s, listensock = (int) arg; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); - listen(*sp, 0); + listen(listensock, 0); for (;;) { - s = accept(*sp, (struct sockaddr *)&from, &fromlen); + s = accept(listensock, (struct sockaddr *)&from, &fromlen); if (s < 0) { debug(DBG_WARN, "accept failed"); continue; } - if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *)&s)) { + if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *) s)) { debug(DBG_ERR, "tcplistener: pthread_create failed"); shutdown(s, SHUT_RDWR); close(s); @@ -364,7 +364,6 @@ void *tcplistener(void *arg) { } pthread_detach(tcpserverth); } - free(sp); return NULL; } #else diff --git a/tls.c b/tls.c index d33fc1b..0564c7e 100644 --- a/tls.c +++ b/tls.c @@ -397,7 +397,7 @@ void *tlsservernew(void *arg) { struct client *client; struct tls *accepted_tls = NULL; - s = *(int *)arg; + s = (int) arg; if (getpeername(s, (struct sockaddr *)&from, &fromlen)) { debug(DBG_DBG, "tlsservernew: getpeername failed, exiting"); goto exit; @@ -458,19 +458,19 @@ exit: void *tlslistener(void *arg) { pthread_t tlsserverth; - int s, *sp = (int *)arg; + int s, listensock = (int) arg; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); - listen(*sp, 0); + listen(listensock, 0); for (;;) { - s = accept(*sp, (struct sockaddr *)&from, &fromlen); + s = accept(listensock, (struct sockaddr *)&from, &fromlen); if (s < 0) { debug(DBG_WARN, "accept failed"); continue; } - if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *)&s)) { + if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *) s)) { debug(DBG_ERR, "tlslistener: pthread_create failed"); shutdown(s, SHUT_RDWR); close(s); @@ -478,7 +478,6 @@ void *tlslistener(void *arg) { } pthread_detach(tlsserverth); } - free(sp); return NULL; } #else diff --git a/udp.c b/udp.c index ff7ad77..dec3667 100644 --- a/udp.c +++ b/udp.c @@ -258,11 +258,11 @@ int clientradputudp(struct server *server, unsigned char *rad) { void *udpclientrd(void *arg) { struct server *server; unsigned char *buf; - int *s = (int *)arg; + int s = (int) arg; for (;;) { server = NULL; - buf = radudpget(*s, NULL, &server, NULL); + buf = radudpget(s, NULL, &server, NULL); replyh(server, buf); } } @@ -348,10 +348,10 @@ void initextraudp() { } if (client4_sock >= 0) - if (pthread_create(&cl4th, &pthread_attr, udpclientrd, (void *)&client4_sock)) + if (pthread_create(&cl4th, &pthread_attr, udpclientrd, (void *) client4_sock)) debugx(1, DBG_ERR, "pthread_create failed"); if (client6_sock >= 0) - if (pthread_create(&cl6th, &pthread_attr, udpclientrd, (void *)&client6_sock)) + if (pthread_create(&cl6th, &pthread_attr, udpclientrd, (void *) client6_sock)) debugx(1, DBG_ERR, "pthread_create failed"); if (find_clconf_type(handle, NULL)) { -- cgit v1.1