forked from github/server
memory leak: free spell components and spells at exit
This commit is contained in:
parent
67135c8ea3
commit
7e9c36b599
|
@ -36,8 +36,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
static critbit_tree cb_spells;
|
static critbit_tree cb_spells;
|
||||||
quicklist * spells;
|
quicklist * spells;
|
||||||
|
|
||||||
|
static void free_spell_cb(void *cbdata) {
|
||||||
|
spell *sp = (spell *)cbdata;
|
||||||
|
free(sp->components);
|
||||||
|
free(sp);
|
||||||
|
}
|
||||||
|
|
||||||
void free_spells(void) {
|
void free_spells(void) {
|
||||||
cb_clear(&cb_spells);
|
cb_clear(&cb_spells);
|
||||||
|
ql_foreach(spells, free_spell_cb);
|
||||||
ql_free(spells);
|
ql_free(spells);
|
||||||
spells = 0;
|
spells = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,11 @@ extern "C" {
|
||||||
void showspells(struct region *r, struct unit *u);
|
void showspells(struct region *r, struct unit *u);
|
||||||
int sp_antimagiczone(struct castorder *co);
|
int sp_antimagiczone(struct castorder *co);
|
||||||
|
|
||||||
extern struct spell * create_spell(const char * name, unsigned int id);
|
struct spell * create_spell(const char * name, unsigned int id);
|
||||||
extern struct spell * find_spell(const char *name);
|
struct spell * find_spell(const char *name);
|
||||||
extern struct spell * find_spellbyid(unsigned int i);
|
struct spell * find_spellbyid(unsigned int i);
|
||||||
extern void add_spell(struct quicklist **slistp, spell * sp);
|
void add_spell(struct quicklist **slistp, spell * sp);
|
||||||
extern void free_spells(void);
|
void free_spells(void);
|
||||||
|
|
||||||
/** globals **/
|
/** globals **/
|
||||||
extern struct attrib_type at_unitdissolve;
|
extern struct attrib_type at_unitdissolve;
|
||||||
|
|
|
@ -40,6 +40,7 @@ void test_updatespells(CuTest * tc)
|
||||||
CuAssertPtrNotNull(tc, f->spellbook);
|
CuAssertPtrNotNull(tc, f->spellbook);
|
||||||
CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells));
|
CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells));
|
||||||
CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp));
|
CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp));
|
||||||
|
free_spellbook(book);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue