From 517f8e3f816d7594ef6d458b5805be9b31eada0b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Jan 2006 21:50:57 +0000 Subject: [PATCH] fixed some memory leaks --- src/common/gamecode/laws.c | 13 ++++++++----- src/common/gamecode/laws.h | 1 - src/common/kernel/eressea.h | 1 - src/common/kernel/names.c | 2 +- src/common/kernel/unit.c | 1 + src/common/kernel/unit.h | 1 + src/common/modules/autoseed.c | 14 ++++++++++++-- src/eressea/main.c | 1 + src/eressea/server.cpp | 1 + 9 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 93ce3b001..a6f354e1c 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3435,7 +3435,8 @@ new_units (void) init_tokens(makeord); skip_token(); if (getparam(u->faction->locale) == P_TEMP) { - char * name; + const char * token; + char * name = NULL; int g, alias; order ** newordersp; @@ -3462,8 +3463,10 @@ new_units (void) } alias = getid(); - name = strdup(getstrtoken()); - if (name && strlen(name)==0) name = NULL; + token = getstrtoken(); + if (token && strlen(token)>0) { + name = strdup(token); + } u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u); if (name!=NULL) free(name); fset(u2, UFL_ISNEW); @@ -3807,8 +3810,8 @@ age_factions(void) for (f = factions; f; f = f->next) { ++f->age; if (f->age < NewbieImmunity()) { - add_message(&f->msgs, new_message(f, - "newbieimmunity%i:turns", NewbieImmunity() - f->age)); + ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns", + NewbieImmunity() - f->age)); } } } diff --git a/src/common/gamecode/laws.h b/src/common/gamecode/laws.h index b45c9b3e9..68e9b90a9 100644 --- a/src/common/gamecode/laws.h +++ b/src/common/gamecode/laws.h @@ -30,7 +30,6 @@ int getoption(void); int wanderoff(struct region * r, int p); void demographics(void); void last_orders(void); -void stripunit(struct unit * u); void find_address(void); void update_guards(void); diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 11c798e52..589940d08 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -996,7 +996,6 @@ extern void parse(keyword_t kword, int (*dofun)(struct unit *, struct order *), void verify_data(void); void stripfaction(struct faction * f); -void stripunit(struct unit * u); void freestrlist(strlist * s); int change_hitpoints(struct unit *u, int value); diff --git a/src/common/kernel/names.c b/src/common/kernel/names.c index 407652be0..829fd803a 100644 --- a/src/common/kernel/names.c +++ b/src/common/kernel/names.c @@ -550,7 +550,7 @@ drachen_name(const unit *u) if (anzahl > 1) { sprintf(name, "Die %sn von %s", t+4, rname(u->region, NULL)); } else { - char *n = malloc(32*sizeof(char)); + char n[32]; strcpy(n, silbe1[rand() % SIL1]); strcat(n, silbe2[rand() % SIL2]); diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index df9986d18..f00c584dc 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1199,6 +1199,7 @@ stripunit(unit * u) { free(u->name); free(u->display); + free_order(u->thisorder); free_orders(&u->orders); if(u->skills) free(u->skills); while (u->items) { diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index adb3f0391..fb1bfc215 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -216,6 +216,7 @@ extern void set_number(struct unit * u, int count); extern boolean learn_skill(struct unit * u, skill_t sk, double chance); extern int invisible(const struct unit *target, const struct unit * viewer); +extern void stripunit(struct unit * u); #ifdef __cplusplus } diff --git a/src/common/modules/autoseed.c b/src/common/modules/autoseed.c index ea3400dfc..33f979f9b 100644 --- a/src/common/modules/autoseed.c +++ b/src/common/modules/autoseed.c @@ -471,6 +471,13 @@ island_size(region * r) return size; } +void +free_newfaction(newfaction * nf) +{ + free(nf->email); + free(nf->password); + free(nf); +} /** create new island with up to nsize players * returns the number of players placed on the new island. */ @@ -631,15 +638,18 @@ autoseed(newfaction ** players, int nsize, boolean new_island) } /* remove duplicate email addresses */ - nfp = players; + nfp = &nextf->next; while (*nfp) { newfaction * nf = *nfp; if (strcmp(nextf->email, nf->email)==0) { *nfp = nf->next; - if (nextf!=nf) free(nf); + free_newfaction(nf); } else nfp = &nf->next; } + *players = nextf; + free_newfaction(nextf); + ++psize; --nsize; --isize; diff --git a/src/eressea/main.c b/src/eressea/main.c index b7b45aed5..b8c7710fc 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -337,6 +337,7 @@ game_done(void) while (planes) { plane * pl = planes; planes = planes->next; + free(pl->name); free(pl); } creport_cleanup(); diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 1e8239d4b..d6387e395 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -395,6 +395,7 @@ game_done(void) while (planes) { plane * pl = planes; planes = planes->next; + free(pl->name); free(pl); }