diff --git a/src/json.test.c b/src/json.test.c index 5b3f9813e..53e7cf336 100644 --- a/src/json.test.c +++ b/src/json.test.c @@ -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) { diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index 1dc8e86e8..7e74c5cbb 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -57,6 +57,7 @@ static void test_build_requires_materials(CuTest *tc) { i_change(&u->items, itype, 2); CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1)); CuAssertIntEquals(tc, 1, i_get(u->items, itype)); + test_cleanup(); } static void test_build_requires_building(CuTest *tc) { @@ -78,6 +79,7 @@ static void test_build_requires_building(CuTest *tc) { CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1)); btype->maxcapacity = 0; CuAssertIntEquals_Msg(tc, "cannot build when production building capacity exceeded", EBUILDINGREQ, build(u, &bf.cons, 0, 1)); + test_cleanup(); } static void test_build_failure_missing_skill(CuTest *tc) { @@ -89,6 +91,7 @@ static void test_build_failure_missing_skill(CuTest *tc) { rtype = bf.cons.materials[0].rtype; i_change(&u->items, rtype->itype, 1); CuAssertIntEquals(tc, ENEEDSKILL, build(u, &bf.cons, 1, 1)); + test_cleanup(); } static void test_build_failure_low_skill(CuTest *tc) { @@ -101,6 +104,7 @@ static void test_build_failure_low_skill(CuTest *tc) { i_change(&u->items, rtype->itype, 1); set_level(u, SK_ARMORER, bf.cons.minskill-1); CuAssertIntEquals(tc, ELOWSKILL, build(u, &bf.cons, 0, 10)); + test_cleanup(); } static void test_build_failure_completed(CuTest *tc) { @@ -115,6 +119,7 @@ static void test_build_failure_completed(CuTest *tc) { bf.cons.maxsize = 1; CuAssertIntEquals(tc, ECOMPLETE, build(u, &bf.cons, bf.cons.maxsize, 10)); CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype)); + test_cleanup(); } static void test_build_limits(CuTest *tc) { @@ -202,6 +207,7 @@ static void test_build_building_no_materials(CuTest *tc) { CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, 0)); CuAssertPtrEquals(tc, 0, u->region->buildings); CuAssertPtrEquals(tc, 0, u->building); + test_cleanup(); } static void test_build_building_with_golem(CuTest *tc) { @@ -220,6 +226,7 @@ static void test_build_building_with_golem(CuTest *tc) { CuAssertPtrNotNull(tc, u->region->buildings); CuAssertIntEquals(tc, 1, u->region->buildings->size); CuAssertIntEquals(tc, 0, u->number); + test_cleanup(); } static void test_build_building_success(CuTest *tc) { @@ -243,6 +250,7 @@ static void test_build_building_success(CuTest *tc) { CuAssertPtrEquals(tc, u->region->buildings, u->building); CuAssertIntEquals(tc, 1, u->building->size); CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype)); + test_cleanup(); } CuSuite *get_build_suite(void) diff --git a/src/kernel/building.c b/src/kernel/building.c index ca45d85a9..bd3463744 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -92,8 +92,14 @@ void bt_register(building_type * type) ql_push(&buildingtypes, (void *)type); } +void free_buildingtype(void *ptr) { + building_type *btype =(building_type *)ptr; + free(btype->_name); + free(btype); +} + void free_buildingtypes(void) { - ql_foreach(buildingtypes, free); + ql_foreach(buildingtypes, free_buildingtype); ql_free(buildingtypes); buildingtypes = 0; } diff --git a/src/kernel/building.h b/src/kernel/building.h index 488e8f691..cf80de84f 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -49,7 +49,7 @@ extern "C" { #define BTF_NAMECHANGE 0x100 /* name and description can be changed more than once */ typedef struct building_type { - const char *_name; + char *_name; int flags; /* flags */ int capacity; /* Kapazität pro Größenpunkt */ diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index edbcce98b..2295c8193 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -22,6 +22,8 @@ static void test_register_building(CuTest * tc) bt_register(btype); CuAssertPtrNotNull(tc, bt_find("herp")); +// free(btype->_name); +// free(btype); test_cleanup(); } diff --git a/src/kernel/ship.c b/src/kernel/ship.c index b0fc8e06c..ad2ff7541 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -238,7 +238,8 @@ void free_ship(ship * s) free(s); } -static void free_shiptype(ship_type *stype) { +static void free_shiptype(void *ptr) { + ship_type *stype = (ship_type *)ptr; free(stype->_name); free(stype); } diff --git a/src/market.test.c b/src/market.test.c index bb2c682ba..781577ff0 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -17,6 +17,7 @@ #include #include +#include static void test_market_curse(CuTest * tc) { @@ -45,7 +46,7 @@ static void test_market_curse(CuTest * tc) set_param(&global.parameters, "rules.region_owners", "1"); btype = (building_type *)calloc(1, sizeof(building_type)); - btype->_name = "market"; + btype->_name = _strdup("market"); bt_register(btype); terrain = get_terrain("plain"); diff --git a/src/tests.test.c b/src/tests.test.c index 7e36b193e..fc2097516 100644 --- a/src/tests.test.c +++ b/src/tests.test.c @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -45,6 +46,8 @@ static void test_recreate_world(CuTest * tc) CuAssertPtrEquals(tc, default_locale, get_locale("de")); CuAssertPtrNotNull(tc, default_locale); CuAssertPtrNotNull(tc, findregion(0, 0)); + CuAssertPtrNotNull(tc, get_terrain("plain")); + CuAssertPtrNotNull(tc, get_terrain("ocean")); CuAssertPtrNotNull(tc, (void *)rt_find("horse")); CuAssertPtrNotNull(tc, get_resourcetype(R_HORSE)); CuAssertPtrNotNull(tc, (void *)rt_find("money")); @@ -56,6 +59,8 @@ static void test_recreate_world(CuTest * tc) test_cleanup(); CuAssertPtrEquals(tc, 0, get_locale("de")); + CuAssertPtrEquals(tc, 0, (void*)get_terrain("plain")); + CuAssertPtrEquals(tc, 0, (void*)get_terrain("ocean")); CuAssertPtrEquals(tc, 0, (void*)rt_find("horse")); CuAssertPtrEquals(tc, 0, (void*)get_resourcetype(R_HORSE)); CuAssertPtrNotNull(tc, (void *)rt_find("money")); diff --git a/src/vortex.c b/src/vortex.c index a44b90172..e01dcd1d2 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -61,7 +61,9 @@ static void a_initdirection(attrib * a) static void a_freedirection(attrib * a) { - free(a->data.v); + spec_direction *d = (spec_direction *)(a->data.v); + free(d->desc); + free(d); } static int a_agedirection(attrib * a)