more casual leak removal.

This commit is contained in:
Enno Rehling 2014-12-31 01:00:10 +01:00
parent 80be0a8e89
commit c39be8d599
10 changed files with 1979 additions and 1931 deletions

View File

@ -1047,23 +1047,24 @@ int get_param_int(const struct param *p, const char *key, int def)
int check_param(const struct param *p, const char *key, const char *searchvalue)
{
int result = 0;
const char *value = get_param(p, key);
if (!value) {
return 0;
}
char *p_value = malloc(sizeof(char)* (strlen(value) + 1));
strcpy(p_value, value);
char *p_value = _strdup(value);
const char *delimiter = " ,;";
char *v = strtok(p_value, delimiter);
while (v != NULL) {
if (strcmp(v, searchvalue) == 0)
{
return 1;
if (strcmp(v, searchvalue) == 0) {
result = 1;
break;
}
v = strtok(NULL, delimiter);
}
return 0;
free(p_value);
return result;
}
static const char *g_datadir;

View File

@ -304,7 +304,7 @@ static void json_ship(cJSON *json, ship_type *st) {
}
break;
case cJSON_Array:
st->coasts = (const terrain_type **)
st->coasts = (terrain_type **)
malloc(sizeof(terrain_type *) * (1+cJSON_GetArraySize(child)));
for (i=0,iter=child->child;iter;iter=iter->next) {
if (iter->type==cJSON_String) {

View File

@ -9,7 +9,6 @@
#include <tests.h>
#include <CuTest.h>
#include <stdlib.h>
#include <string.h>
static void test_create_order(CuTest *tc) {
char cmd[32];
@ -127,8 +126,7 @@ static void test_init_order(CuTest *tc) {
}
static void test_getstrtoken(CuTest *tc) {
char *cmd = _strdup("hurr \"durr\" \"\" \'\'");
init_tokens_str(cmd);
init_tokens_str("hurr \"durr\" \"\" \'\'");
CuAssertStrEquals(tc, "hurr", getstrtoken());
CuAssertStrEquals(tc, "durr", getstrtoken());
CuAssertStrEquals(tc, "", getstrtoken());
@ -139,8 +137,7 @@ static void test_getstrtoken(CuTest *tc) {
}
static void test_skip_token(CuTest *tc) {
char *cmd = _strdup("hurr \"durr\"");
init_tokens_str(cmd);
init_tokens_str("hurr \"durr\"");
skip_token();
CuAssertStrEquals(tc, "durr", getstrtoken());
CuAssertStrEquals(tc, 0, getstrtoken());

View File

@ -241,6 +241,7 @@ void free_ship(ship * s)
static void free_shiptype(void *ptr) {
ship_type *stype = (ship_type *)ptr;
free(stype->_name);
free(stype->coasts);
free(stype);
}

View File

@ -1,7 +1,7 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -27,46 +27,46 @@ extern "C" {
#define DAMAGE_SCALE 100 /* multiplier for sh->damage */
/* ship_type::flags */
/* ship_type::flags */
#define SFL_OPENSEA 0x01
#define SFL_FLY 0x02
#define SFL_NOCOAST 0x04
typedef struct ship_type {
char *_name;
typedef struct ship_type {
char *_name;
int range; /* range in regions */
int flags; /* flags */
int combat; /* modifier for combat */
int range; /* range in regions */
int flags; /* flags */
int combat; /* modifier for combat */
double storm; /* multiplier for chance to drift in storm */
double damage; /* multiplier for damage taken by the ship */
double storm; /* multiplier for chance to drift in storm */
double damage; /* multiplier for damage taken by the ship */
int cabins; /* max. cabins (weight) */
int cargo; /* max. cargo (weight) */
int cabins; /* max. cabins (weight) */
int cargo; /* max. cargo (weight) */
int cptskill; /* min. skill of captain */
int minskill; /* min. skill to sail this (crew) */
int sumskill; /* min. sum of crew+captain */
int cptskill; /* min. skill of captain */
int minskill; /* min. skill to sail this (crew) */
int sumskill; /* min. sum of crew+captain */
int fishing; /* weekly income from fishing */
int fishing; /* weekly income from fishing */
int at_bonus; /* Verändert den Angriffsskill (default: 0) */
int df_bonus; /* Verändert den Verteidigungskill (default: 0) */
float tac_bonus;
int at_bonus; /* Verändert den Angriffsskill (default: 0) */
int df_bonus; /* Verändert den Verteidigungskill (default: 0) */
float tac_bonus;
const struct terrain_type **coasts; /* coast that this ship can land on */
struct terrain_type ** coasts; /* coast that this ship can land on */
struct construction *construction; /* how to build a ship */
} ship_type;
struct construction *construction; /* how to build a ship */
} ship_type;
extern struct quicklist *shiptypes;
extern struct quicklist *shiptypes;
/* Alte Schiffstypen: */
/* Alte Schiffstypen: */
const ship_type *st_find(const char *name);
ship_type *st_get_or_create(const char *name);
void free_shiptypes(void);
const ship_type *st_find(const char *name);
ship_type *st_get_or_create(const char *name);
void free_shiptypes(void);
#define NOSHIP NULL
@ -80,51 +80,51 @@ extern "C" {
#define SFL_SAVEMASK (SF_FLYING)
#define INCOME_FISHING 10
typedef struct ship {
struct ship *next;
struct ship *nexthash;
struct unit * _owner; /* never use directly, always use ship_owner() */
int no;
struct region *region;
char *name;
char *display;
struct attrib *attribs;
int size;
int damage; /* damage in 100th of a point of size */
int flags;
const struct ship_type *type;
direction_t coast;
} ship;
typedef struct ship {
struct ship *next;
struct ship *nexthash;
struct unit * _owner; /* never use directly, always use ship_owner() */
int no;
struct region *region;
char *name;
char *display;
struct attrib *attribs;
int size;
int damage; /* damage in 100th of a point of size */
int flags;
const struct ship_type *type;
direction_t coast;
} ship;
void damage_ship(struct ship * sh, double percent);
void ship_set_owner(struct unit * u);
struct unit *ship_owner(const struct ship *sh);
void ship_update_owner(struct ship * sh);
void damage_ship(struct ship * sh, double percent);
void ship_set_owner(struct unit * u);
struct unit *ship_owner(const struct ship *sh);
void ship_update_owner(struct ship * sh);
extern const char *shipname(const struct ship *self);
extern int shipcapacity(const struct ship *sh);
extern void getshipweight(const struct ship *sh, int *weight, int *cabins);
extern const char *shipname(const struct ship *self);
extern int shipcapacity(const struct ship *sh);
extern void getshipweight(const struct ship *sh, int *weight, int *cabins);
extern ship *new_ship(const struct ship_type *stype, struct region *r,
const struct locale *lang);
extern const char *write_shipname(const struct ship *sh, char *buffer,
size_t size);
extern struct ship *findship(int n);
extern struct ship *findshipr(const struct region *r, int n);
extern ship *new_ship(const struct ship_type *stype, struct region *r,
const struct locale *lang);
extern const char *write_shipname(const struct ship *sh, char *buffer,
size_t size);
extern struct ship *findship(int n);
extern struct ship *findshipr(const struct region *r, int n);
extern const struct ship_type *findshiptype(const char *s,
const struct locale *lang);
extern const struct ship_type *findshiptype(const char *s,
const struct locale *lang);
extern void write_ship_reference(const struct ship *sh,
extern void write_ship_reference(const struct ship *sh,
struct storage *store);
extern void remove_ship(struct ship **slist, struct ship *s);
extern void free_ship(struct ship *s);
extern void free_ships(void);
extern void remove_ship(struct ship **slist, struct ship *s);
extern void free_ship(struct ship *s);
extern void free_ships(void);
extern const char *ship_getname(const struct ship *self);
extern void ship_setname(struct ship *self, const char *name);
int shipspeed(const struct ship *sh, const struct unit *u);
extern const char *ship_getname(const struct ship *self);
extern void ship_setname(struct ship *self, const char *name);
int shipspeed(const struct ship *sh, const struct unit *u);
#ifdef __cplusplus
}

View File

@ -27,6 +27,8 @@ void test_named_spellbooks(CuTest * tc)
sb = create_spellbook(0);
CuAssertPtrNotNull(tc, sb);
CuAssertPtrEquals(tc, 0, sb->name);
spellbook_clear(sb);
free(sb);
sb = create_spellbook("spells");
CuAssertPtrNotNull(tc, sb);

File diff suppressed because it is too large Load Diff

View File

@ -15,10 +15,10 @@ without prior permission by the authors of Eressea.
#ifdef __cplusplus
extern "C" {
#endif
extern void register_xmlreader(void);
extern void register_xmlreader(void);
/* game-specific callbacks */
extern void (*set_spelldata_cb) (struct spell * sp);
/* game-specific callbacks */
extern void(*set_spelldata_cb) (struct spell * sp);
#ifdef __cplusplus
}
#endif

View File

@ -28,7 +28,7 @@ static void test_ship_not_allowed_in_coast(CuTest * tc)
ttype = test_create_terrain("glacier", LAND_REGION | ARCTIC_REGION | WALK_INTO | SAIL_INTO);
otype = test_create_terrain("ocean", SEA_REGION | SAIL_INTO);
stype = test_create_shiptype("derp");
stype->coasts = (const struct terrain_type **)calloc(2, sizeof(const struct terrain_type *));
stype->coasts = (struct terrain_type **)calloc(2, sizeof(struct terrain_type *));
r1 = test_create_region(0, 0, ttype);
r2 = test_create_region(1, 0, otype);

View File

@ -86,6 +86,7 @@ int RunAllTests(void)
log_flags = flags;
fail_count = suite->failCount;
CuSuiteDelete(suite);
kernel_done();
return fail_count;
}