diff options
author | Masaq- <tilt@techie.com> | 2019-02-20 04:13:08 +0000 |
---|---|---|
committer | Masaq- <tilt@techie.com> | 2019-02-20 04:13:08 +0000 |
commit | bbacf7a27f42147ed587c5e59b0f60c76e5248dd (patch) | |
tree | acbb968675ab84bd50c4beb2178b70fff931f34b | |
parent | df3843984dac3f73f31f483ad86a7c24f6551337 (diff) |
fix leaky rings
-rw-r--r-- | src/pdesc.c | 34 | ||||
-rw-r--r-- | src/pdesc.h | 2 | ||||
-rw-r--r-- | src/pkt.c | 3 |
3 files changed, 26 insertions, 13 deletions
diff --git a/src/pdesc.c b/src/pdesc.c index df8df46..72f5081 100644 --- a/src/pdesc.c +++ b/src/pdesc.c @@ -125,7 +125,6 @@ proxy_desc_t *create_and_insert_proxy_desc(uint16_t id_no, uint16_t icmp_id, * Assumes that we hold the chain_lock. */ void remove_proxy_desc(proxy_desc_t *cur, proxy_desc_t *prev) { - int i; struct timeval tt; pt_log(kLog_debug, "Removing proxy descriptor.\n"); @@ -137,16 +136,7 @@ void remove_proxy_desc(proxy_desc_t *cur, proxy_desc_t *prev) { if (cur->buf) free(cur->buf); cur->buf = 0; - for (i=0;i<cur->window_size;i++) { - if (cur->send_ring[i].pkt) - free(cur->send_ring[i].pkt); - cur->send_ring[i].pkt = 0; - if (cur->recv_ring[i]) - free(cur->recv_ring[i]); - cur->recv_ring[i] = 0; - } - free(cur->send_ring); - free(cur->recv_ring); + remove_proxy_desc_rings(cur); close(cur->sock); cur->sock = 0; @@ -161,6 +151,28 @@ void remove_proxy_desc(proxy_desc_t *cur, proxy_desc_t *prev) { num_tunnels--; } +void remove_proxy_desc_rings(proxy_desc_t *cur) { + int i; + for (i=0;i<cur->window_size;i++) { + if (cur->send_ring[i].pkt) + free(cur->send_ring[i].pkt); + cur->send_ring[i].pkt = 0; + if (cur->recv_ring[i]) + free(cur->recv_ring[i]); + cur->recv_ring[i] = 0; + } + free(cur->send_ring); + free(cur->recv_ring); + + cur->recv_idx = 0; + cur->recv_xfer_idx = 0; + cur->send_idx = 0; + cur->send_first_ack = 0; + cur->recv_wait_send = 0; + cur->send_wait_ack = 0; + cur->next_resend_start = 0; +} + forward_desc_t* create_fwd_desc(uint16_t seq_no, uint32_t data_len, char *data) { forward_desc_t *fwd_desc; fwd_desc = (forward_desc_t *) malloc(sizeof(forward_desc_t)+data_len); diff --git a/src/pdesc.h b/src/pdesc.h index a537b9a..169c069 100644 --- a/src/pdesc.h +++ b/src/pdesc.h @@ -175,6 +175,8 @@ proxy_desc_t* create_and_insert_proxy_desc(uint16_t id_no, uint16_t icmp_id, void remove_proxy_desc(proxy_desc_t *cur, proxy_desc_t *prev); +void remove_proxy_desc_rings(proxy_desc_t *cur); + forward_desc_t* create_fwd_desc(uint16_t seq_no, uint32_t data_len, char *data); int queue_packet(int icmp_sock, uint8_t type, char *buf, int num_bytes, @@ -427,9 +427,8 @@ void handle_extended_options(void *vcur) { proxy_desc_t *cur = (proxy_desc_t *)vcur; if (cur->extended_options[0] > 0) { + remove_proxy_desc_rings(cur); cur->window_size = cur->extended_options[0]; - free(cur->send_ring); - free(cur->recv_ring); cur->send_ring = calloc(cur->window_size, sizeof(icmp_desc_t)); cur->recv_ring = calloc(cur->window_size, sizeof(forward_desc_t *)); pt_log(kLog_verbose, "Received extended option for window size %d \n", cur->window_size); |