Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/tcptable.c | 74 ++++++++++++++++++++++++----------------------------------
1 file changed, 30 insertions(+), 44 deletions(-)
diff --git a/src/tcptable.c b/src/tcptable.c
index f613e31..9f29c5b 100644
--- a/src/tcptable.c
+++ b/src/tcptable.c
@@ -911,60 +911,46 @@ static void destroy_closed_entries(struct tcptable *table)
table->closedtail = NULL;
}
-/*
- * Kill the entire TCP table
- */
-void destroytcptable(struct tcptable *table)
+static void destroy_tcp_entries(struct tcptable *table)
{
- struct tcptableent *ctemp;
- struct tcptableent *c_next_entry;
- struct tcp_hashentry *hashtemp;
- struct tcp_hashentry *hashtemp_next;
-
- unsigned int i;
+ struct tcptableent *ptmp = table->head;
- /*
- * Destroy main TCP table
- */
+ while (ptmp != NULL) {
+ struct tcptableent *ctmp = ptmp->next_entry;
- if (table->head != NULL) {
- ctemp = table->head;
- c_next_entry = table->head->next_entry;
+ rate_destroy(&ptmp->rate);
+ free(ptmp);
+ ptmp = ctmp;
+ }
+ table->head = NULL;
+ table->tail = NULL;
+}
- while (ctemp != NULL) {
- rate_destroy(&ctemp->rate);
- free(ctemp);
- ctemp = c_next_entry;
+static void destroy_hash_entries(struct tcptable *table)
+{
+ for (unsigned int i = 0; i < ENTRIES_IN_HASH_TABLE; i++) {
+ struct tcp_hashentry *ptmp = table->hash_table[i];
+ while (ptmp != NULL) {
+ struct tcp_hashentry *ctmp = ptmp->next_entry;
- if (c_next_entry != NULL)
- c_next_entry = c_next_entry->next_entry;
+ free(ptmp);
+ ptmp = ctmp;
}
+ table->hash_table[i] = NULL;
}
- /*
- * Destroy list of closed entries
- */
-
- destroy_closed_entries(table);
-
- /*
- * Destroy hash table
- */
+}
- for (i = 0; i <= ENTRIES_IN_HASH_TABLE - 1; i++) {
- if (table->hash_table[i] != NULL) {
- hashtemp = table->hash_table[i];
- hashtemp_next = table->hash_table[i]->next_entry;
+/* kill the entire TCP table */
+void destroytcptable(struct tcptable *table)
+{
+ /* destroy main TCP table */
+ destroy_tcp_entries(table);
- while (hashtemp != NULL) {
- free(hashtemp);
- hashtemp = hashtemp_next;
+ /* destroy list of closed entries */
+ destroy_closed_entries(table);
- if (hashtemp_next != NULL)
- hashtemp_next =
- hashtemp_next->next_entry;
- }
- }
- }
+ /* destroy hash table */
+ destroy_hash_entries(table);
}
/*
--
1.8.4