[Fix] Fixed double free if an invalid faction was loaded.

This commit is contained in:
Allanis 2013-09-11 23:40:59 +01:00
parent 98eac283ef
commit 7b77faa53e

View File

@ -461,6 +461,7 @@ int pfaction_save(xmlTextWriterPtr writer) {
int pfaction_load(xmlNodePtr parent) { int pfaction_load(xmlNodePtr parent) {
xmlNodePtr node, cur; xmlNodePtr node, cur;
char* str; char* str;
int faction;
node = parent->xmlChildrenNode; node = parent->xmlChildrenNode;
@ -470,7 +471,9 @@ int pfaction_load(xmlNodePtr parent) {
do { do {
if(xml_isNode(cur, "factions")) { if(xml_isNode(cur, "factions")) {
xmlr_attr(cur, "name", str); xmlr_attr(cur, "name", str);
faction_stack[faction_get(str)].player = xml_getInt(cur); faction = faction_get(str);
if(faction != -1) /* Faction is valid. */
faction_stack[faction].player = xml_getInt(cur);
free(str); free(str);
} }
} while(xml_nextNode(cur)); } while(xml_nextNode(cur));