@@ -28,7 +28,7 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
2828 std::string digit;
2929 std::string file;
3030 std::istream *iss;
31- struct fuzzy_hash_chunk * chunk, * t;
31+ std::shared_ptr< fuzzy_hash_chunk> chunk, t;
3232 std::string err;
3333
3434 auto pos = m_param.find_last_of (' ' );
@@ -55,11 +55,10 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
5555 }
5656
5757 for (std::string line; std::getline (*iss, line); ) {
58- chunk = (struct fuzzy_hash_chunk *)calloc (1 ,
59- sizeof (struct fuzzy_hash_chunk ));
58+ chunk = std::make_shared<fuzzy_hash_chunk>();
6059
61- chunk->data = strdup (line.c_str ());
62- chunk->next = NULL ;
60+ chunk->data = std::shared_ptr< char >( strdup (line.c_str ()), free );
61+ chunk->next = nullptr ;
6362
6463 if (m_head == NULL ) {
6564 m_head = chunk;
@@ -83,23 +82,11 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
8382#endif
8483}
8584
86- FuzzyHash::~FuzzyHash () {
87- struct fuzzy_hash_chunk *c = m_head;
88- while (c) {
89- struct fuzzy_hash_chunk *t = c;
90- free (c->data );
91- c->data = NULL ;
92- c = c->next ;
93- free (t);
94- }
95- m_head = NULL ;
96- }
97-
98-
9985bool FuzzyHash::evaluate (Transaction *t, const std::string &str) {
10086#ifdef WITH_SSDEEP
10187 char result[FUZZY_MAX_RESULT];
102- struct fuzzy_hash_chunk *chunk = m_head;
88+ std::shared_ptr<fuzzy_hash_chunk> chunk = m_head;
89+
10390
10491 if (fuzzy_hash_buf ((const unsigned char *)str.c_str (),
10592 str.size (), result)) {
@@ -108,7 +95,7 @@ bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
10895 }
10996
11097 while (chunk != NULL ) {
111- int i = fuzzy_compare (chunk->data , result);
98+ int i = fuzzy_compare (chunk->data . get () , result);
11299 if (i >= m_threshold) {
113100 ms_dbg_a (t, 4 , " Fuzzy hash: matched " \
114101 " with score: " + std::to_string (i) + " ." );
0 commit comments