forked from github/server
properly free items at cleanup.
This commit is contained in:
parent
a55cb13924
commit
228983202d
|
@ -45,6 +45,7 @@ static void test_export_no_regions(CuTest * tc) {
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
CuAssertStrEquals(tc, "{}", strip(buf));
|
CuAssertStrEquals(tc, "{}", strip(buf));
|
||||||
mstream_done(&out);
|
mstream_done(&out);
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, region **_r) {
|
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"));
|
CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "name"));
|
||||||
CuAssertStrEquals(tc, r->land->name, attr->valuestring);
|
CuAssertStrEquals(tc, r->land->name, attr->valuestring);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_export_ocean_region(CuTest * tc) {
|
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);
|
json = export_a_region(tc, terrain, 0);
|
||||||
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "name"));
|
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "name"));
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_export_no_factions(CuTest * tc) {
|
static void test_export_no_factions(CuTest * tc) {
|
||||||
|
@ -119,6 +122,7 @@ static void test_export_no_factions(CuTest * tc) {
|
||||||
buf[len]=0;
|
buf[len]=0;
|
||||||
CuAssertStrEquals(tc, "{}", strip(buf));
|
CuAssertStrEquals(tc, "{}", strip(buf));
|
||||||
mstream_done(&out);
|
mstream_done(&out);
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_json_suite(void) {
|
CuSuite *get_json_suite(void) {
|
||||||
|
|
|
@ -1167,10 +1167,7 @@ static item *default_spoil(const struct race *rc, int size)
|
||||||
return itm;
|
return itm;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_TESTS
|
int free_itype(item_type *itype) {
|
||||||
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));
|
|
||||||
free(itype->construction);
|
free(itype->construction);
|
||||||
free(itype->_appearance[0]);
|
free(itype->_appearance[0]);
|
||||||
free(itype->_appearance[1]);
|
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;
|
resource_type *rtype;
|
||||||
cb_get_kv(match, &rtype, sizeof(rtype));
|
cb_get_kv(match, &rtype, sizeof(rtype));
|
||||||
free(rtype->_name);
|
free(rtype->_name);
|
||||||
|
if (rtype->itype) {
|
||||||
|
free_itype(rtype->itype);
|
||||||
|
}
|
||||||
free(rtype);
|
free(rtype);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_clear_resources(void)
|
void free_resources(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -1201,7 +1201,6 @@ void test_clear_resources(void)
|
||||||
cb_clear(rnames + i);
|
cb_clear(rnames + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void register_resources(void)
|
void register_resources(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -324,9 +324,7 @@ extern "C" {
|
||||||
extern void register_item_useonother(int (*foo) (struct unit *, int,
|
extern void register_item_useonother(int (*foo) (struct unit *, int,
|
||||||
const struct item_type *, int, struct order *), const char *name);
|
const struct item_type *, int, struct order *), const char *name);
|
||||||
|
|
||||||
#ifndef DISABLE_TESTS
|
void free_resources(void);
|
||||||
void test_clear_resources(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ void spellbook_clear(spellbook *sb)
|
||||||
free(sbe);
|
free(sbe);
|
||||||
}
|
}
|
||||||
ql_free(sb->spells);
|
ql_free(sb->spells);
|
||||||
|
free(sb->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int spellbook_foreach(spellbook *sb, int (*callback)(spellbook_entry *, void *), void * data)
|
int spellbook_foreach(spellbook *sb, int (*callback)(spellbook_entry *, void *), void * data)
|
||||||
|
|
|
@ -58,7 +58,7 @@ struct unit *test_create_unit(struct faction *f, struct region *r)
|
||||||
void test_cleanup(void)
|
void test_cleanup(void)
|
||||||
{
|
{
|
||||||
free_terrains();
|
free_terrains();
|
||||||
test_clear_resources();
|
free_resources();
|
||||||
global.functions.maintenance = NULL;
|
global.functions.maintenance = NULL;
|
||||||
global.functions.wage = NULL;
|
global.functions.wage = NULL;
|
||||||
default_locale = 0;
|
default_locale = 0;
|
||||||
|
@ -75,7 +75,6 @@ terrain_type *
|
||||||
test_create_terrain(const char * name, unsigned int flags)
|
test_create_terrain(const char * name, unsigned int flags)
|
||||||
{
|
{
|
||||||
terrain_type * t = get_or_create_terrain(name);
|
terrain_type * t = get_or_create_terrain(name);
|
||||||
t->_name = _strdup(name);
|
|
||||||
t->flags = flags;
|
t->flags = flags;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue