Fix packet filter memory leaks

This commit is contained in:
Jon Siwek 2019-12-30 10:52:50 -08:00
parent 7db84dfcb6
commit a961f0b4c4
5 changed files with 52 additions and 20 deletions

View file

@ -18,8 +18,8 @@ private:
};
public:
PrefixTable() { tree = New_Patricia(128); }
~PrefixTable() { Destroy_Patricia(tree, 0); }
PrefixTable() { tree = New_Patricia(128); delete_function = nullptr; }
~PrefixTable() { Destroy_Patricia(tree, delete_function); }
// Addr in network byte order. If data is zero, acts like a set.
// Returns ptr to old data if already existing.
@ -43,7 +43,10 @@ public:
void* Remove(const IPAddr& addr, int width);
void* Remove(const Val* value);
void Clear() { Clear_Patricia(tree, 0); }
void Clear() { Clear_Patricia(tree, delete_function); }
// Sets a function to call for each node when table is cleared/destroyed.
void SetDeleteFunction(data_fn_t del_fn) { delete_function = del_fn; }
iterator InitIterator();
void* GetNext(iterator* i);
@ -53,4 +56,5 @@ private:
static IPPrefix PrefixToIPPrefix(prefix_t* p);
patricia_tree_t* tree;
data_fn_t delete_function;
};