Fix a memory leak

This commit is contained in:
bʰedoh₂ swé 2024-06-10 01:15:19 +05:00
parent 3a3014f9a3
commit 3128d3c646

View File

@ -14,7 +14,7 @@ bool replace(tSyntaxElement* tree, tProcessingData* pdata) {
if (tree->type == TOKEN)
if (strcmp(tree->content.string, pd->data.replace.replacethis) == 0) {
didreplace = true;
free(tree->content.string);
free(tree->content.none);
tSyntaxElement* clone = se_clone_no_next(pd->data.replace.replacewiththis, tree);
tree->content = clone->content;
tree->type = clone->type;
@ -53,8 +53,10 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
void process(tSyntaxElement* tree, tProcessingData* pdata) {
tProcessingData* pd = pdata;
bool deffound = false;
tProcessingData* firstpd = NULL;
if (pd == NULL) {
pd = calloc(1,sizeof(tProcessingData));
firstpd = pd;
}
deffound = process_find(tree, &pd);
if (tree->next != NULL) {
@ -72,4 +74,8 @@ void process(tSyntaxElement* tree, tProcessingData* pdata) {
break;
}
}
if (pd != pdata)
free(pd);
if (firstpd != pd && firstpd != NULL)
free(firstpd);
}