Merge pull request #507 from ennorehling/hotfix/bug-2201-remove_empty_factions

Hotfix bug 2201, crash E3 turn 351
This commit is contained in:
Enno Rehling 2016-04-03 13:23:29 +02:00
commit 13156a47a4
3 changed files with 8 additions and 7 deletions

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 3
#define VERSION_MINOR 8
#define VERSION_BUILD 7
#define VERSION_BUILD 8

View File

@ -74,9 +74,6 @@ faction *factions;
static void free_faction(faction * f)
{
funhash(f);
if (f->alliance && f->alliance->_leader == f) {
setalliance(f, 0);
}
if (f->msgs) {
free_messagelist(f->msgs->begin);
free(f->msgs);
@ -454,7 +451,7 @@ void destroyfaction(faction ** fp)
}
#endif
if (f->alliance && f->alliance->_leader == f) {
if (f->alliance) {
setalliance(f, 0);
}
@ -681,8 +678,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

@ -13,6 +13,7 @@
#include "monster.h"
#include <CuTest.h>
#include <tests.h>
#include <quicklist.h>
#include <assert.h>
#include <stdio.h>
@ -46,8 +47,10 @@ static void test_remove_empty_factions_alliance(CuTest *tc) {
al = makealliance(0, "Hodor");
setalliance(f, al);
CuAssertPtrEquals(tc, f, alliance_get_leader(al));
CuAssertIntEquals(tc, 1, ql_length(al->members));
remove_empty_factions();
CuAssertPtrEquals(tc, 0, al->_leader);
CuAssertIntEquals(tc, 0, ql_length(al->members));
test_cleanup();
}
@ -61,6 +64,9 @@ static void test_remove_empty_factions(CuTest *tc) {
f = test_create_faction(0);
fno = f->no;
remove_empty_factions();
CuAssertIntEquals(tc, false, f->_alive);
CuAssertPtrEquals(tc, fm, factions);
CuAssertPtrEquals(tc, NULL, fm->next);
CuAssertPtrEquals(tc, 0, findfaction(fno));
CuAssertPtrEquals(tc, fm, get_monsters());
test_cleanup();