diff --git a/flow_db.c b/flow_db.c index 8663980..88ce971 100644 --- a/flow_db.c +++ b/flow_db.c @@ -40,9 +40,25 @@ struct ip_pair *pairs [HASH_TBL_SIZE]; void init_hash_table(void) { - bzero(pairs, sizeof(struct ip_pair *) * HASH_TBL_SIZE); + memset(pairs, 0, sizeof(struct ip_pair *) * HASH_TBL_SIZE); } +void free_hash_table(void) +{ + size_t b; + struct ip_pair *curp; + + for (b = 0; b < HASH_TBL_SIZE; b++) { + while (pairs[b]) { + curp = pairs[b]; + pairs[b] = pairs[b]->next; + reset_pdf(&curp->pdf); + free(curp); + } + } + + init_hash_table(); +} static unsigned int hashf(const void *key, size_t sz, unsigned int hash) { diff --git a/pkt2flow.c b/pkt2flow.c index 7bd23ba..7ab5bcd 100644 --- a/pkt2flow.c +++ b/pkt2flow.c @@ -329,5 +329,6 @@ int main(int argc, char *argv[]) init_hash_table(); process_trace(); close_trace_files(); + free_hash_table(); exit(0); } diff --git a/pkt2flow.h b/pkt2flow.h index 1f93935..61a2cd9 100644 --- a/pkt2flow.h +++ b/pkt2flow.h @@ -93,6 +93,11 @@ char *new_file_name(uint32_t src_ip, uint32_t dst_ip, */ void init_hash_table(void); +/* + * Free the flow has table + */ +void free_hash_table(void); + /* * Search for the flow in the flow hash table with specific 4-tuple; * If the flow item exists in the hash table, the pointer to the ip_pair will be