From 96f9270b7f2d744545d141e5a48931bf60cce51a Mon Sep 17 00:00:00 2001 From: frekky Date: Fri, 21 Aug 2015 23:24:53 +0800 Subject: [PATCH] Removed unhelpful coding errors. --- src/client.c | 3 ++- src/user.c | 21 ++++++++++----------- src/window.c | 7 ++++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/client.c b/src/client.c index b3e52c3..f27f606 100644 --- a/src/client.c +++ b/src/client.c @@ -397,7 +397,6 @@ send_next_frag(int fd) /* Get next fragment to send */ f = window_get_next_sending_fragment(outbuf, next_downstream_ack); - window_tick(outbuf); if (f == NULL) { if (is_sending()) { /* There is stuff to send but we're out of sync, so send a ping @@ -433,6 +432,8 @@ send_next_frag(int fd) datacmc = 0; send_query(fd, (char *)buf); + + window_tick(outbuf); } static void diff --git a/src/user.c b/src/user.c index 22a0132..bf95f53 100644 --- a/src/user.c +++ b/src/user.c @@ -135,12 +135,16 @@ find_available_user() for (int u = 0; u < usercount; u++) { /* Not used at all or not used in one minute */ if (!user_active(u)) { + struct tun_user *user = &users[u]; + if (user->incoming) window_buffer_destroy(user->incoming); + if (user->outgoing) window_buffer_destroy(user->outgoing); /* reset all stats */ - memset(&users[u], 0, sizeof(users[u])); - users[u].active = 1; - users[u].last_pkt = time(NULL); - users[u].fragsize = MAX_FRAGSIZE; - users[u].conn = CONN_DNS_NULL; + user->active = 1; + user->authenticated = 0; + user->authenticated_raw = 0; + user->last_pkt = time(NULL); + user->fragsize = MAX_FRAGSIZE; + user->conn = CONN_DNS_NULL; return u; } } @@ -177,12 +181,7 @@ check_user_and_ip(int userid, struct query *q) if (userid < 0 || userid >= created_users ) { return 1; } - if (!users[userid].active || users[userid].disabled) { - return 1; - } - if (users[userid].last_pkt + 60 < time(NULL)) { - return 1; - } + if (!user_active(userid)) return 1; /* return early if IP checking is disabled */ if (!check_ip) { diff --git a/src/window.c b/src/window.c index c29a5b5..45bc2fd 100644 --- a/src/window.c +++ b/src/window.c @@ -56,7 +56,8 @@ window_buffer_init(size_t length, unsigned windowsize, unsigned fragsize, int di void window_buffer_destroy(struct frag_buffer *w) { - free(w->frags); + if (!w) return; + if (w->frags) free(w->frags); free(w); } @@ -120,7 +121,7 @@ window_reassemble_data(struct frag_buffer *w, uint8_t *data, unsigned maxlen, in // warnx("chunk_start pointing to non-start fragment (%u)!", w->frags[w->chunk_start].seqID); return 0; } - *compression = 1; + if (compression) *compression = 1; fragment *f; size_t i, curseq; @@ -139,7 +140,7 @@ window_reassemble_data(struct frag_buffer *w, uint8_t *data, unsigned maxlen, in memcpy(dest, f->data, MIN(fraglen, maxlen)); dest += fraglen; datalen += fraglen; - *compression &= f->compressed & 1; + if (compression) *compression &= f->compressed & 1; if (f->compressed != *compression) { warnx("Inconsistent compression flags in chunk. Not reassembling!"); return 0;