Skip to content

Commit b7698d6

Browse files
author
Felipe Zimmerle
committed
Fix memory leak in @fuzzyHash
1 parent 68152d8 commit b7698d6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/operators/fuzzy_hash.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
8484
#endif
8585
}
8686

87+
FuzzyHash::~FuzzyHash() {
88+
struct fuzzy_hash_chunk *c = m_head;
89+
while (c) {
90+
struct fuzzy_hash_chunk *t = c;
91+
free(c->data);
92+
c->data = NULL;
93+
c = c->next;
94+
free (t);
95+
}
96+
m_head = NULL;
97+
}
8798

8899

89100
bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {

src/operators/fuzzy_hash.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace operators {
2929

3030

3131
struct fuzzy_hash_chunk {
32-
const char *data;
32+
char *data;
3333
struct fuzzy_hash_chunk *next;
3434
};
3535

@@ -44,6 +44,8 @@ class FuzzyHash : public Operator {
4444
: Operator("FuzzyHash", param),
4545
m_head(NULL),
4646
m_threshold(0) { }
47+
~FuzzyHash();
48+
4749
bool evaluate(Transaction *transaction, const std::string &std) override;
4850

4951
bool init(const std::string &param, std::string *error) override;

0 commit comments

Comments
 (0)