properly free items at cleanup.

This commit is contained in:
Enno Rehling 2014-12-30 23:49:50 +01:00
parent a55cb13924
commit 228983202d
5 changed files with 12 additions and 11 deletions

View File

@ -45,6 +45,7 @@ static void test_export_no_regions(CuTest * tc) {
buf[len] = '\0';
CuAssertStrEquals(tc, "{}", strip(buf));
mstream_done(&out);
test_cleanup();
}
static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, region **_r) {
@ -93,6 +94,7 @@ static void test_export_land_region(CuTest * tc) {
CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "name"));
CuAssertStrEquals(tc, r->land->name, attr->valuestring);
cJSON_Delete(json);
test_cleanup();
}
static void test_export_ocean_region(CuTest * tc) {
@ -103,6 +105,7 @@ static void test_export_ocean_region(CuTest * tc) {
json = export_a_region(tc, terrain, 0);
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "name"));
cJSON_Delete(json);
test_cleanup();
}
static void test_export_no_factions(CuTest * tc) {
@ -119,6 +122,7 @@ static void test_export_no_factions(CuTest * tc) {
buf[len]=0;
CuAssertStrEquals(tc, "{}", strip(buf));
mstream_done(&out);
test_cleanup();
}
CuSuite *get_json_suite(void) {

View File

@ -1167,10 +1167,7 @@ static item *default_spoil(const struct race *rc, int size)
return itm;
}
#ifndef DISABLE_TESTS
int free_itype_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
item_type *itype;
cb_get_kv(match, &itype, sizeof(itype));
int free_itype(item_type *itype) {
free(itype->construction);
free(itype->_appearance[0]);
free(itype->_appearance[1]);
@ -1182,11 +1179,14 @@ int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbd
resource_type *rtype;
cb_get_kv(match, &rtype, sizeof(rtype));
free(rtype->_name);
if (rtype->itype) {
free_itype(rtype->itype);
}
free(rtype);
return 0;
}
void test_clear_resources(void)
void free_resources(void)
{
int i;
@ -1201,7 +1201,6 @@ void test_clear_resources(void)
cb_clear(rnames + i);
}
}
#endif
void register_resources(void)
{

View File

@ -324,9 +324,7 @@ extern "C" {
extern void register_item_useonother(int (*foo) (struct unit *, int,
const struct item_type *, int, struct order *), const char *name);
#ifndef DISABLE_TESTS
void test_clear_resources(void);
#endif
void free_resources(void);
#ifdef __cplusplus
}

View File

@ -45,6 +45,7 @@ void spellbook_clear(spellbook *sb)
free(sbe);
}
ql_free(sb->spells);
free(sb->name);
}
int spellbook_foreach(spellbook *sb, int (*callback)(spellbook_entry *, void *), void * data)

View File

@ -58,7 +58,7 @@ struct unit *test_create_unit(struct faction *f, struct region *r)
void test_cleanup(void)
{
free_terrains();
test_clear_resources();
free_resources();
global.functions.maintenance = NULL;
global.functions.wage = NULL;
default_locale = 0;
@ -75,7 +75,6 @@ terrain_type *
test_create_terrain(const char * name, unsigned int flags)
{
terrain_type * t = get_or_create_terrain(name);
t->_name = _strdup(name);
t->flags = flags;
return t;
}