Skip to content

Commit 6025c2e

Browse files
committed
Merge pull request #862 from wazuh/fix_leaks
Fixed some memory leaks at analysisd
2 parents 2944c12 + 6bd0c43 commit 6025c2e

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/analysisd/decoders/decode-xml.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ static int os_setdecoderids(const char *p_name)
100100
nnode->id = p_id;
101101

102102
/* Set parent name */
103-
nnode->name = tmp_name;
103+
free(nnode->name);
104+
nnode->name = strdup(tmp_name);
104105
}
105106

106107
/* Id cannot be 0 */
@@ -203,12 +204,14 @@ int ReadDecodeXML(const char *file)
203204
}
204205

205206
/* Zero NULL_decoder */
206-
os_calloc(1, sizeof(OSDecoderInfo), NULL_Decoder_tmp);
207-
NULL_Decoder_tmp->id = 0;
208-
NULL_Decoder_tmp->type = SYSLOG;
209-
NULL_Decoder_tmp->name = NULL;
210-
NULL_Decoder_tmp->fts = 0;
211-
NULL_Decoder = NULL_Decoder_tmp;
207+
if (!NULL_Decoder) {
208+
os_calloc(1, sizeof(OSDecoderInfo), NULL_Decoder_tmp);
209+
NULL_Decoder_tmp->id = 0;
210+
NULL_Decoder_tmp->type = SYSLOG;
211+
NULL_Decoder_tmp->name = NULL;
212+
NULL_Decoder_tmp->fts = 0;
213+
NULL_Decoder = NULL_Decoder_tmp;
214+
}
212215

213216
i = 0;
214217
while (node[i]) {
@@ -751,4 +754,3 @@ char *_loadmemory(char *at, char *str)
751754
}
752755
return (NULL);
753756
}
754-

src/analysisd/rules.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ int Rules_OP_ReadRules(const char *rulefile)
11171117
free(if_matched_regex);
11181118
if_matched_regex = NULL;
11191119
}
1120+
OS_ClearNode(rule_opt);
11201121
} /* end of elements block */
11211122

11221123
/* Assign an active response to the rule */
@@ -1761,4 +1762,3 @@ static int doesRuleExist(int sid, RuleNode *r_node)
17611762

17621763
return (0);
17631764
}
1764-

src/config/rules-config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ int Read_Rules(XML_NODE node, void *configp, __attribute__((unused)) void *mailp
174174
}
175175
}
176176

177+
OSRegex_FreePattern(&regex);
177178
closedir(dfd);
178179
/* Sort just then newly added items */
179180
qsort(Config->decoders + start_point , decoders_size - start_point - 1, sizeof(char *), cmpr);
@@ -242,6 +243,7 @@ int Read_Rules(XML_NODE node, void *configp, __attribute__((unused)) void *mailp
242243
}
243244
}
244245

246+
OSRegex_FreePattern(&regex);
245247
closedir(dfd);
246248
/* Sort just then newly added items */
247249
qsort(Config->includes + start_point , rules_size - start_point - 1, sizeof(char *), cmpr);
@@ -255,4 +257,3 @@ int Read_Rules(XML_NODE node, void *configp, __attribute__((unused)) void *mailp
255257
}
256258
return (0);
257259
}
258-

src/shared/store_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ int OSStore_Put(OSStore *list, const char *key, void *data)
346346
if ((chk_rc = strcmp(list->cur_node->key, key)) >= 0) {
347347
/* Duplicate entry */
348348
if (chk_rc == 0) {
349+
free(newnode->key);
349350
free(newnode);
350351
return (1);
351352
}
@@ -380,4 +381,3 @@ int OSStore_Put(OSStore *list, const char *key, void *data)
380381

381382
return (1);
382383
}
383-

0 commit comments

Comments
 (0)