@@ -28,7 +28,7 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
28
28
std::string digit;
29
29
std::string file;
30
30
std::istream *iss;
31
- struct fuzzy_hash_chunk * chunk, * t;
31
+ std::shared_ptr< fuzzy_hash_chunk> chunk, t;
32
32
std::string err;
33
33
34
34
auto pos = m_param.find_last_of (' ' );
@@ -55,11 +55,10 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
55
55
}
56
56
57
57
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>();
60
59
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 ;
63
62
64
63
if (m_head == NULL ) {
65
64
m_head = chunk;
@@ -84,22 +83,15 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
84
83
}
85
84
86
85
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 ;
86
+
96
87
}
97
88
98
89
99
90
bool FuzzyHash::evaluate (Transaction *t, const std::string &str) {
100
91
#ifdef WITH_SSDEEP
101
92
char result[FUZZY_MAX_RESULT];
102
- struct fuzzy_hash_chunk *chunk = m_head;
93
+ std::shared_ptr<fuzzy_hash_chunk> chunk = m_head;
94
+
103
95
104
96
if (fuzzy_hash_buf ((const unsigned char *)str.c_str (),
105
97
str.size (), result)) {
@@ -108,7 +100,7 @@ bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
108
100
}
109
101
110
102
while (chunk != NULL ) {
111
- int i = fuzzy_compare (chunk->data , result);
103
+ int i = fuzzy_compare (chunk->data . get () , result);
112
104
if (i >= m_threshold) {
113
105
ms_dbg_a (t, 4 , " Fuzzy hash: matched " \
114
106
" with score: " + std::to_string (i) + " ." );
0 commit comments