diff options
author | Linus Nordberg <linus@nordu.net> | 2016-04-18 15:02:38 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2016-09-21 12:17:52 +0200 |
commit | 5acfcb4c7ce94482660dedb710e0b1f2ab8e5578 (patch) | |
tree | 92624c1abeb9274fc14e1174a6eb86cddce9f9b9 | |
parent | 6c1f37d727afb31ac3fa4af4a4158993897d402d (diff) |
Stomp less on other threads memory.
See RADSECPROXY-64.
-rw-r--r-- | radsecproxy.c | 10 | ||||
-rw-r--r-- | tcp.c | 9 | ||||
-rw-r--r-- | tls.c | 11 | ||||
-rw-r--r-- | 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); @@ -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 @@ -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 @@ -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)) { |