diff options
| -rw-r--r-- | src/base/modules.c | 36 | ||||
| -rw-r--r-- | src/base/space.c | 7 | ||||
| -rw-r--r-- | src/modules/modWall.c | 8 |
3 files changed, 49 insertions, 2 deletions
diff --git a/src/base/modules.c b/src/base/modules.c index 6f572ed..58eed95 100644 --- a/src/base/modules.c +++ b/src/base/modules.c @@ -76,6 +76,32 @@ static mod_reg_t *mod_register (char *name, mod_sym_t *sym) return mod; } +/* free all unnecessary memory blocks from module's reglist */ +static void mod_destroy () +{ + unsigned i; + for (;;) { + i = 0; + + mod_reg_t *mod; + for (mod = mod_reglist.next; mod != &mod_reglist; mod = mod->next) { + /* delete entry from context */ + mod->next->prev = mod->prev; + mod->prev->next = mod->next; + + free (mod->name); + free (mod); + + i ++; + + break; + } + + if (!i) + break; + } +} + static mod_reg_t *mod_find (char *name) { mod_reg_t *mod; @@ -105,6 +131,11 @@ static module_t *newModule(char *name) ret->name = strdup (name); + if (!ret->name) { + free (ret); + return 0; + } + ret->fce_init = mod->sym->init; #ifndef PUBLIC_SERVER ret->fce_draw = mod->sym->draw; @@ -134,9 +165,10 @@ static int destroyModule(module_t *p) debug("Unloading module [%s]", p->name); p->fce_destroy(); + free(p->name); free(p); - + return 0; } @@ -275,4 +307,6 @@ void module_quit() { list_destroy_item(listModule, destroyModule); share_function_quit(); + + mod_destroy (); } diff --git a/src/base/space.c b/src/base/space.c index 5d725ef..cc9ac48 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -39,6 +39,10 @@ space_t *space_new(int w, int h, int segW, int segH, int i, j; new = malloc(sizeof(space_t)); + + if (!new) + return 0; + memset(new, 0, sizeof(space_t)); new->w = w / segW + 1; @@ -95,6 +99,9 @@ void space_add(space_t *p, void *item) if (!p || !item) return; + if (!p->zone) + return; + p->getStatus(item, &id, &x, &y, &w, &h); getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); diff --git a/src/modules/modWall.c b/src/modules/modWall.c index c6b1141..0e4ff02 100644 --- a/src/modules/modWall.c +++ b/src/modules/modWall.c @@ -225,14 +225,16 @@ static void cmd_wall(char *line) export_fce->fce_arena_get_current()->h, 320, 240, getStatusWall, setStatusWall); + } #ifndef PUBLIC_SERVER + if (spaceImgWall == NULL) { spaceImgWall = space_new(export_fce->fce_arena_get_current()->w, export_fce->fce_arena_get_current()->h, 320, 240, getStatusImgWall, setStatusImgWall); -#endif } +#endif space_add(spaceWall, new); @@ -351,6 +353,10 @@ static int destroy() space_destroy(spaceImgWall); #endif list_destroy(listWall); + + spaceWall = 0; + spaceImgWall = 0; + return 0; } |