summaryrefslogtreecommitdiff
path: root/tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/tcp.c b/tcp.c
index 6870a9c..e903cc5 100644
--- a/tcp.c
+++ b/tcp.c
@@ -317,6 +317,7 @@ void *tcpservernew(void *arg) {
struct client *client;
s = *(int *)arg;
+ free(arg);
if (getpeername(s, (struct sockaddr *)&from, &fromlen)) {
debug(DBG_DBG, "tcpservernew: getpeername failed, exiting");
goto exit;
@@ -344,26 +345,32 @@ exit:
void *tcplistener(void *arg) {
pthread_t tcpserverth;
- 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(&tcpserverth, &pthread_attr, tcpservernew, (void *) s)) {
+ s_arg = malloc(sizeof(s));
+ if (!s_arg)
+ debugx(1, DBG_ERR, "malloc failed");
+ *s_arg = s;
+ if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *) s_arg)) {
debug(DBG_ERR, "tcplistener: pthread_create failed");
+ free(s_arg);
shutdown(s, SHUT_RDWR);
close(s);
continue;
}
pthread_detach(tcpserverth);
}
+ free(sp);
return NULL;
}
#else