fix spellbook leak

This commit is contained in:
Enno Rehling 2016-02-27 13:10:23 +01:00
parent be54c60a34
commit 257ae38749
3 changed files with 23 additions and 8 deletions

View File

@ -1188,6 +1188,7 @@ static item *default_spoil(const struct race *rc, int size)
}
static void free_itype(item_type *itype) {
assert(itype);
free(itype->construction);
free(itype->_appearance[0]);
free(itype->_appearance[1]);
@ -1195,14 +1196,14 @@ static void free_itype(item_type *itype) {
}
static void free_wtype(weapon_type *wtype) {
assert(wtype);
free(wtype->damage[0]);
free(wtype->damage[1]);
free(wtype);
}
int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
resource_type *rtype;
cb_get_kv(match, &rtype, sizeof(rtype));
void free_rtype(resource_type *rtype) {
assert(rtype);
if (rtype->wtype) {
free_wtype(rtype->wtype);
}
@ -1214,6 +1215,12 @@ int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbd
}
free(rtype->_name);
free(rtype);
}
int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
resource_type *rtype;
cb_get_kv(match, &rtype, sizeof(rtype));
free_rtype(rtype);
return 0;
}

View File

@ -36,8 +36,7 @@ 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;
static void free_spell(spell *sp) {
free(sp->syntax);
free(sp->parameter);
free(sp->sname);
@ -45,6 +44,10 @@ static void free_spell_cb(void *cbdata) {
free(sp);
}
static void free_spell_cb(void *cbdata) {
free_spell((spell *)cbdata);
}
void free_spells(void) {
cb_clear(&cb_spells);
ql_foreach(spells, free_spell_cb);

View File

@ -317,6 +317,12 @@ static void setup_spell_fixture(spell_fixture * spf) {
spf->sbe = spellbook_get(spf->spb, spf->sp);
}
static void cleanup_spell_fixture(spell_fixture *spf) {
spellbook_clear(spf->spb);
free(spf->spb);
test_cleanup();
}
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
stream strm;
char buf[1024];
@ -405,9 +411,8 @@ static void test_write_spell_syntax(CuTest *tc) {
set_parameter(spell, "kc+");
check_spell_syntax(tc, "kc+", &spell,
" ZAUBERE \"Testzauber\" ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr>\n [<snr> ...] | BURG <bnr> [<bnr> ...] )");
spellbook_clear(spell.spb);
free(spell.spb);
test_cleanup();
cleanup_spell_fixture(&spell);
}
CuSuite *get_reports_suite(void)