forked from github/server
move static variable cleanup to kernel_done.
clean up some more.
This commit is contained in:
parent
ef5ce04335
commit
d84ed1f89d
|
@ -55,10 +55,6 @@ void game_done(void)
|
|||
free_functions();
|
||||
free_config();
|
||||
free_locales();
|
||||
message_done();
|
||||
equipment_done();
|
||||
reports_done();
|
||||
curses_done();
|
||||
kernel_done();
|
||||
}
|
||||
|
||||
|
|
|
@ -401,24 +401,24 @@ building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
|
|||
|
||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
||||
// PEASANT: "b", "ba", "bau", "baue", "p", "pe", "pea", "peas"
|
||||
static int *forbidden_ids;
|
||||
|
||||
int forbiddenid(int id)
|
||||
{
|
||||
static int *forbid = NULL;
|
||||
static size_t len;
|
||||
size_t i;
|
||||
if (id <= 0)
|
||||
return 1;
|
||||
if (!forbid) {
|
||||
if (!forbidden_ids) {
|
||||
while (forbidden[len])
|
||||
++len;
|
||||
forbid = calloc(len, sizeof(int));
|
||||
forbidden_ids = calloc(len, sizeof(int));
|
||||
for (i = 0; i != len; ++i) {
|
||||
forbid[i] = atoi36(forbidden[i]);
|
||||
forbidden_ids[i] = atoi36(forbidden[i]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i != len; ++i)
|
||||
if (id == forbid[i])
|
||||
if (id == forbidden_ids[i])
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -739,8 +739,15 @@ void kernel_done(void)
|
|||
/* calling this function releases memory assigned to static variables, etc.
|
||||
* calling it is optional, e.g. a release server will most likely not do it.
|
||||
*/
|
||||
xml_done();
|
||||
attrib_done();
|
||||
item_done();
|
||||
message_done();
|
||||
equipment_done();
|
||||
reports_done();
|
||||
curses_done();
|
||||
crmessage_done();
|
||||
translation_done();
|
||||
free_attribs();
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
|
@ -1079,7 +1086,6 @@ void free_config(void) {
|
|||
void free_gamedata(void)
|
||||
{
|
||||
int i;
|
||||
free_donations();
|
||||
|
||||
for (i = 0; i != MAXLOCALES; ++i) {
|
||||
if (defaults[i]) {
|
||||
|
@ -1087,6 +1093,10 @@ void free_gamedata(void)
|
|||
defaults[i] = 0;
|
||||
}
|
||||
}
|
||||
free(forbidden_ids);
|
||||
forbidden_ids = NULL;
|
||||
|
||||
free_donations();
|
||||
free_factions();
|
||||
free_units();
|
||||
free_regions();
|
||||
|
|
|
@ -232,6 +232,7 @@ void equipment_done(void) {
|
|||
free(eq->name);
|
||||
if (eq->spellbook) {
|
||||
spellbook_clear(eq->spellbook);
|
||||
free(eq->spellbook);
|
||||
}
|
||||
// TODO: items, subsets
|
||||
free(eq);
|
||||
|
|
|
@ -518,6 +518,11 @@ static item *icache;
|
|||
static int icache_size;
|
||||
#define ICACHE_MAX 100
|
||||
|
||||
void item_done(void) {
|
||||
i_freeall(&icache);
|
||||
icache_size = 0;
|
||||
}
|
||||
|
||||
void i_free(item * i)
|
||||
{
|
||||
if (icache_size >= ICACHE_MAX) {
|
||||
|
|
|
@ -59,6 +59,8 @@ extern "C" {
|
|||
#define NMF_PLURAL 0x01
|
||||
#define NMF_APPEARANCE 0x02
|
||||
|
||||
void item_done(void);
|
||||
|
||||
typedef int(*rtype_uchange) (struct unit * user,
|
||||
const struct resource_type * rtype, int delta);
|
||||
typedef int(*rtype_uget) (const struct unit * user,
|
||||
|
|
|
@ -412,6 +412,7 @@ void a_write_orig(struct storage *store, const attrib * attribs, const void *own
|
|||
WRITE_TOK(store, "end");
|
||||
}
|
||||
|
||||
void free_attribs(void) {
|
||||
void attrib_done(void) {
|
||||
cb_clear(&cb_deprecated);
|
||||
memset(at_hash, 0, sizeof at_hash);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ extern "C" {
|
|||
int a_read(struct gamedata *data, attrib ** attribs, void *owner);
|
||||
void a_write(struct storage *store, const attrib * attribs, const void *owner);
|
||||
|
||||
void free_attribs(void);
|
||||
void attrib_done(void);
|
||||
|
||||
#define DEFAULT_AGE NULL
|
||||
#define DEFAULT_INIT NULL
|
||||
|
|
|
@ -32,6 +32,15 @@ typedef struct tsf_list {
|
|||
|
||||
static tsf_list *tostringfs;
|
||||
|
||||
void crmessage_done(void) {
|
||||
tsf_list **tsp = &tostringfs;
|
||||
while (*tsp) {
|
||||
tsf_list *ts = *tsp;
|
||||
*tsp = ts->next;
|
||||
free(ts);
|
||||
}
|
||||
}
|
||||
|
||||
static tostring_f tsf_find(const char *name)
|
||||
{
|
||||
if (name != NULL) {
|
||||
|
|
|
@ -22,6 +22,8 @@ extern "C" {
|
|||
struct message;
|
||||
struct message_type;
|
||||
|
||||
void crmessage_done(void);
|
||||
|
||||
typedef int(*tostring_f) (variant data, char *buffer, const void *userdata);
|
||||
void tsf_register(const char *name, tostring_f fun);
|
||||
/* registers a new type->string-function */
|
||||
|
|
|
@ -89,6 +89,15 @@ typedef struct xml_reader {
|
|||
|
||||
static xml_reader *xmlReaders;
|
||||
|
||||
void xml_done(void) {
|
||||
xml_reader ** xrp = &xmlReaders;
|
||||
while (*xrp) {
|
||||
xml_reader *xr = *xrp;
|
||||
*xrp = xr->next;
|
||||
free(xr);
|
||||
}
|
||||
}
|
||||
|
||||
void xml_register_callback(xml_callback callback)
|
||||
{
|
||||
xml_reader *reader = (xml_reader *)malloc(sizeof(xml_reader));
|
||||
|
|
|
@ -21,13 +21,17 @@ extern "C" {
|
|||
/* new xml functions: */
|
||||
#include <libxml/tree.h>
|
||||
|
||||
typedef int (*xml_callback) (xmlDocPtr);
|
||||
extern void xml_register_callback(xml_callback callback);
|
||||
extern double xml_fvalue(xmlNodePtr node, const char *name, double dflt);
|
||||
extern int xml_ivalue(xmlNodePtr node, const char *name, int dflt);
|
||||
extern bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt);
|
||||
|
||||
typedef int (*xml_callback) (xmlDocPtr);
|
||||
|
||||
void xml_register_callback(xml_callback callback);
|
||||
double xml_fvalue(xmlNodePtr node, const char *name, double dflt);
|
||||
int xml_ivalue(xmlNodePtr node, const char *name, int dflt);
|
||||
bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt);
|
||||
#endif
|
||||
extern int read_xml(const char *filename, const char *catalog);
|
||||
|
||||
void xml_done(void);
|
||||
int read_xml(const char *filename, const char *catalog);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue