Skip to content

Commit

Permalink
Free hashtable on normal exits to make spotting memleaks easier
Browse files Browse the repository at this point in the history
  • Loading branch information
ecsv committed Feb 12, 2014
1 parent deb99c5 commit 50a164d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion flow_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions pkt2flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,6 @@ int main(int argc, char *argv[])
init_hash_table();
process_trace();
close_trace_files();
free_hash_table();
exit(0);
}
5 changes: 5 additions & 0 deletions pkt2flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50a164d

Please sign in to comment.