fixed some memory leaks

This commit is contained in:
Enno Rehling 2006-01-02 21:50:57 +00:00
parent 83e9b7a994
commit 517f8e3f81
9 changed files with 25 additions and 10 deletions

View file

@ -3435,7 +3435,8 @@ new_units (void)
init_tokens(makeord); init_tokens(makeord);
skip_token(); skip_token();
if (getparam(u->faction->locale) == P_TEMP) { if (getparam(u->faction->locale) == P_TEMP) {
char * name; const char * token;
char * name = NULL;
int g, alias; int g, alias;
order ** newordersp; order ** newordersp;
@ -3462,8 +3463,10 @@ new_units (void)
} }
alias = getid(); alias = getid();
name = strdup(getstrtoken()); token = getstrtoken();
if (name && strlen(name)==0) name = NULL; if (token && strlen(token)>0) {
name = strdup(token);
}
u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u); u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u);
if (name!=NULL) free(name); if (name!=NULL) free(name);
fset(u2, UFL_ISNEW); fset(u2, UFL_ISNEW);
@ -3807,8 +3810,8 @@ age_factions(void)
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
++f->age; ++f->age;
if (f->age < NewbieImmunity()) { if (f->age < NewbieImmunity()) {
add_message(&f->msgs, new_message(f, ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns",
"newbieimmunity%i:turns", NewbieImmunity() - f->age)); NewbieImmunity() - f->age));
} }
} }
} }

View file

@ -30,7 +30,6 @@ int getoption(void);
int wanderoff(struct region * r, int p); int wanderoff(struct region * r, int p);
void demographics(void); void demographics(void);
void last_orders(void); void last_orders(void);
void stripunit(struct unit * u);
void find_address(void); void find_address(void);
void update_guards(void); void update_guards(void);

View file

@ -996,7 +996,6 @@ extern void parse(keyword_t kword, int (*dofun)(struct unit *, struct order *),
void verify_data(void); void verify_data(void);
void stripfaction(struct faction * f); void stripfaction(struct faction * f);
void stripunit(struct unit * u);
void freestrlist(strlist * s); void freestrlist(strlist * s);
int change_hitpoints(struct unit *u, int value); int change_hitpoints(struct unit *u, int value);

View file

@ -550,7 +550,7 @@ drachen_name(const unit *u)
if (anzahl > 1) { if (anzahl > 1) {
sprintf(name, "Die %sn von %s", t+4, rname(u->region, NULL)); sprintf(name, "Die %sn von %s", t+4, rname(u->region, NULL));
} else { } else {
char *n = malloc(32*sizeof(char)); char n[32];
strcpy(n, silbe1[rand() % SIL1]); strcpy(n, silbe1[rand() % SIL1]);
strcat(n, silbe2[rand() % SIL2]); strcat(n, silbe2[rand() % SIL2]);

View file

@ -1199,6 +1199,7 @@ stripunit(unit * u)
{ {
free(u->name); free(u->name);
free(u->display); free(u->display);
free_order(u->thisorder);
free_orders(&u->orders); free_orders(&u->orders);
if(u->skills) free(u->skills); if(u->skills) free(u->skills);
while (u->items) { while (u->items) {

View file

@ -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 boolean learn_skill(struct unit * u, skill_t sk, double chance);
extern int invisible(const struct unit *target, const struct unit * viewer); extern int invisible(const struct unit *target, const struct unit * viewer);
extern void stripunit(struct unit * u);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -471,6 +471,13 @@ island_size(region * r)
return size; return size;
} }
void
free_newfaction(newfaction * nf)
{
free(nf->email);
free(nf->password);
free(nf);
}
/** create new island with up to nsize players /** create new island with up to nsize players
* returns the number of players placed on the new island. * 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 */ /* remove duplicate email addresses */
nfp = players; nfp = &nextf->next;
while (*nfp) { while (*nfp) {
newfaction * nf = *nfp; newfaction * nf = *nfp;
if (strcmp(nextf->email, nf->email)==0) { if (strcmp(nextf->email, nf->email)==0) {
*nfp = nf->next; *nfp = nf->next;
if (nextf!=nf) free(nf); free_newfaction(nf);
} }
else nfp = &nf->next; else nfp = &nf->next;
} }
*players = nextf;
free_newfaction(nextf);
++psize; ++psize;
--nsize; --nsize;
--isize; --isize;

View file

@ -337,6 +337,7 @@ game_done(void)
while (planes) { while (planes) {
plane * pl = planes; plane * pl = planes;
planes = planes->next; planes = planes->next;
free(pl->name);
free(pl); free(pl);
} }
creport_cleanup(); creport_cleanup();

View file

@ -395,6 +395,7 @@ game_done(void)
while (planes) { while (planes) {
plane * pl = planes; plane * pl = planes;
planes = planes->next; planes = planes->next;
free(pl->name);
free(pl); free(pl);
} }