fix some memory leaks

- t_free does not free
- free_factions frees the wrong list
- cleanup after attrib test
This commit is contained in:
Enno Rehling 2016-03-10 13:27:08 +01:00
parent d43265f937
commit 7e98384542
3 changed files with 5 additions and 3 deletions

View File

@ -342,7 +342,7 @@ static faction *dead_factions;
void free_flist(faction **fp) {
faction * flist = *fp;
for (flist = factions; flist;) {
while (flist) {
faction *f = flist;
flist = f->next;
free_faction(f);
@ -681,8 +681,6 @@ void remove_empty_factions(void)
if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
log_debug("dead: %s", factionname(f));
destroyfaction(fp);
free_faction(f);
free(f);
}
else {
fp = &(*fp)->next;

View File

@ -49,6 +49,7 @@ static void test_attrib_remove_self(CuTest * tc) {
CuAssertPtrEquals(tc, 0, alist->nexttype);
CuAssertIntEquals(tc, 1, a_remove(&alist, alist));
CuAssertPtrEquals(tc, a, alist);
a_removeall(&alist, NULL);
}

View File

@ -63,6 +63,7 @@ int read_triggers(struct gamedata *data, trigger ** tp)
break;
case AT_READ_FAIL:
t_free(*tp);
free(*tp);
*tp = NULL;
break;
default:
@ -107,6 +108,7 @@ int handle_triggers(trigger ** triggers, void *param)
if (t->type->handle(t, param) != 0) {
*tp = t->next;
t_free(t);
free(t);
}
else
tp = &t->next;
@ -260,6 +262,7 @@ const trigger_type * tt)
if (t->type == tt) {
*tp = t->next;
t_free(t);
free(t);
}
else
tp = &t->next;