forked from github/server
fix spellbook leak
This commit is contained in:
parent
be54c60a34
commit
257ae38749
|
@ -1188,6 +1188,7 @@ static item *default_spoil(const struct race *rc, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_itype(item_type *itype) {
|
static void free_itype(item_type *itype) {
|
||||||
|
assert(itype);
|
||||||
free(itype->construction);
|
free(itype->construction);
|
||||||
free(itype->_appearance[0]);
|
free(itype->_appearance[0]);
|
||||||
free(itype->_appearance[1]);
|
free(itype->_appearance[1]);
|
||||||
|
@ -1195,14 +1196,14 @@ static void free_itype(item_type *itype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_wtype(weapon_type *wtype) {
|
static void free_wtype(weapon_type *wtype) {
|
||||||
|
assert(wtype);
|
||||||
free(wtype->damage[0]);
|
free(wtype->damage[0]);
|
||||||
free(wtype->damage[1]);
|
free(wtype->damage[1]);
|
||||||
free(wtype);
|
free(wtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
|
void free_rtype(resource_type *rtype) {
|
||||||
resource_type *rtype;
|
assert(rtype);
|
||||||
cb_get_kv(match, &rtype, sizeof(rtype));
|
|
||||||
if (rtype->wtype) {
|
if (rtype->wtype) {
|
||||||
free_wtype(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->_name);
|
||||||
free(rtype);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,7 @@ 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) {
|
static void free_spell(spell *sp) {
|
||||||
spell *sp = (spell *)cbdata;
|
|
||||||
free(sp->syntax);
|
free(sp->syntax);
|
||||||
free(sp->parameter);
|
free(sp->parameter);
|
||||||
free(sp->sname);
|
free(sp->sname);
|
||||||
|
@ -45,6 +44,10 @@ static void free_spell_cb(void *cbdata) {
|
||||||
free(sp);
|
free(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_spell_cb(void *cbdata) {
|
||||||
|
free_spell((spell *)cbdata);
|
||||||
|
}
|
||||||
|
|
||||||
void free_spells(void) {
|
void free_spells(void) {
|
||||||
cb_clear(&cb_spells);
|
cb_clear(&cb_spells);
|
||||||
ql_foreach(spells, free_spell_cb);
|
ql_foreach(spells, free_spell_cb);
|
||||||
|
|
|
@ -317,6 +317,12 @@ static void setup_spell_fixture(spell_fixture * spf) {
|
||||||
spf->sbe = spellbook_get(spf->spb, spf->sp);
|
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) {
|
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
|
||||||
stream strm;
|
stream strm;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
@ -405,9 +411,8 @@ static void test_write_spell_syntax(CuTest *tc) {
|
||||||
set_parameter(spell, "kc+");
|
set_parameter(spell, "kc+");
|
||||||
check_spell_syntax(tc, "kc+", &spell,
|
check_spell_syntax(tc, "kc+", &spell,
|
||||||
" ZAUBERE \"Testzauber\" ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr>\n [<snr> ...] | BURG <bnr> [<bnr> ...] )");
|
" ZAUBERE \"Testzauber\" ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr>\n [<snr> ...] | BURG <bnr> [<bnr> ...] )");
|
||||||
spellbook_clear(spell.spb);
|
|
||||||
free(spell.spb);
|
cleanup_spell_fixture(&spell);
|
||||||
test_cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_reports_suite(void)
|
CuSuite *get_reports_suite(void)
|
||||||
|
|
Loading…
Reference in New Issue