diff --git a/src/battle.c b/src/battle.c index 4105cf73f..ad613a69f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1858,10 +1858,13 @@ static void do_combatspell(troop at) static void do_extra_spell(troop at, const att * a) { - const spell *sp = a->data.sp; + const spell *sp = spellref_get(a->data.sp); - if (sp->cast == NULL) { - log_error("spell '%s' has no function.\n", sp->sname); + if (!sp) { + log_error("no such spell: '%s'", a->data.sp->name); + } + else if (sp->cast == NULL) { + log_error("spell '%s' has no function.", sp->sname); } else { assert(a->level > 0); diff --git a/src/kernel/race.c b/src/kernel/race.c index c18761dcd..1bdba8a1b 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -182,7 +182,12 @@ void racelist_insert(struct race_list **rl, const struct race *r) void free_races(void) { while (races) { + int i; race * rc = races->next; + + for (i = 0; races->attack[i].type!=AT_NONE; ++i) { + spellref_free(races->attack[i].data.sp); + } spellref_free(races->precombatspell); free_params(&races->parameters); free(xrefs); diff --git a/src/kernel/race.h b/src/kernel/race.h index 496dfa763..19b7b7ad3 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -105,7 +105,7 @@ extern "C" { int type; union { const char *dice; - const struct spell *sp; + struct spellref *sp; } data; int flags; int level; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 238b04227..36fe2d7f8 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1889,11 +1889,11 @@ static int parse_races(xmlDocPtr doc) xmlFree(propValue); } else { - attack->data.sp = xml_spell(node, "spell"); + attack->data.sp = xml_spellref(node, "spell"); if (attack->data.sp) { attack->level = xml_ivalue(node, "level", 0); if (attack->level <= 0) { - log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->sname, rc->_name, attack->level); + log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->name, rc->_name, attack->level); } } }