memory leak: free spell components and spells at exit

This commit is contained in:
Enno Rehling 2015-10-13 22:02:58 +02:00
parent 67135c8ea3
commit 7e9c36b599
3 changed files with 13 additions and 5 deletions

View File

@ -36,8 +36,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static critbit_tree cb_spells;
quicklist * spells;
static void free_spell_cb(void *cbdata) {
spell *sp = (spell *)cbdata;
free(sp->components);
free(sp);
}
void free_spells(void) {
cb_clear(&cb_spells);
ql_foreach(spells, free_spell_cb);
ql_free(spells);
spells = 0;
}

View File

@ -50,11 +50,11 @@ extern "C" {
void showspells(struct region *r, struct unit *u);
int sp_antimagiczone(struct castorder *co);
extern struct spell * create_spell(const char * name, unsigned int id);
extern struct spell * find_spell(const char *name);
extern struct spell * find_spellbyid(unsigned int i);
extern void add_spell(struct quicklist **slistp, spell * sp);
extern void free_spells(void);
struct spell * create_spell(const char * name, unsigned int id);
struct spell * find_spell(const char *name);
struct spell * find_spellbyid(unsigned int i);
void add_spell(struct quicklist **slistp, spell * sp);
void free_spells(void);
/** globals **/
extern struct attrib_type at_unitdissolve;

View File

@ -40,6 +40,7 @@ void test_updatespells(CuTest * tc)
CuAssertPtrNotNull(tc, f->spellbook);
CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells));
CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp));
free_spellbook(book);
test_cleanup();
}