In void destroy_db() in db.c, I found this code snippet that's meant to traverse the list of triggers and free them. In the code comments, there is talk of a memory leak. I don't know if this was meant to fix that.
Code:
/* Triggers */
for (cnt=0; cnt < top_of_trigt; cnt++) {
if (trig_index[cnt]->proto) {
/* make sure to nuke the command list (memory leak) */
/* free_trigger() doesn't free the command list */
if (trig_index[cnt]->proto->cmdlist) {
struct cmdlist_element *i, *j;
i = trig_index[cnt]->proto->cmdlist;
while (i) {
j = i;
if (i->cmd)
free(i->cmd);
free(i);
i = j;
}
}
free_trigger(trig_index[cnt]->proto);
}
free(trig_index[cnt]);
}
free(trig_index);
}
I changed it to the following. I think that it might work better. Unfortunately, I have to rebuild my main device, so I can't test it by building and running TBA on it. Thoughts?
Code:
/* Triggers */
for (cnt=0; cnt < top_of_trigt; cnt++) {
if (trig_index[cnt]->proto) {
/* make sure to nuke the command list (memory leak) */
/* free_trigger() doesn't free the command list */
if (trig_index[cnt]->proto->cmdlist) {
struct cmdlist_element *i, *j;
i = trig_index[cnt]->proto->cmdlist;
while (i) {
j = i->next;
if (i->cmd) {
free(i->cmd);
i->cmd = NULL;
}
free(j);
j = NULL;
}
}
free_trigger(trig_index[cnt]->proto);
}
free(trig_index[cnt]);
trig_index[cnt] = NULL;
}
free(trig_index);
trig_index = NULL;
}