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);
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));
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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]);

View File

@ -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) {

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

View File

@ -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;

View File

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

View File

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