misc. memory leaks removed

This commit is contained in:
Enno Rehling 2005-06-11 08:09:55 +00:00
parent 8242e9ed41
commit 1a1dc417c4
17 changed files with 95 additions and 14 deletions

View File

@ -399,7 +399,8 @@ cr_order(variant var, char * buffer, const void * userdata)
}
*wp++ = '\"';
*wp++ = 0;
/* sprintf(buffer, "\"%s\"", cmd); */
free(cmd);
}
else strcpy(buffer, "\"\"");
return 0;

View File

@ -73,12 +73,6 @@
# include <items/seed.h>
#endif
typedef struct donation {
struct donation *next;
struct faction *f1, *f2;
int amount;
} donation;
typedef struct request {
struct request * next;
struct unit *unit;
@ -372,6 +366,11 @@ free_recruitments(recruitment * recruits)
while (recruits) {
recruitment * rec = recruits;
recruits = rec->next;
while (rec->requests) {
request * req = rec->requests;
rec->requests = req->next;
free(req);
}
free(rec);
}
}
@ -845,8 +844,8 @@ report_donations(void)
{
region * r;
for (r=regions;r;r=r->next) {
donation * sp;
for (sp = r->donations; sp; sp = sp->next) {
while (r->donations) {
donation * sp = r->donations;
if (sp->amount > 0) {
struct message * msg = msg_message("donation",
"from to amount", sp->f1, sp->f2, sp->amount);
@ -854,6 +853,8 @@ report_donations(void)
r_addmessage(r, sp->f2, msg);
msg_release(msg);
}
r->donations = sp->next;
free(sp);
}
}
}

View File

@ -979,4 +979,5 @@ plan_monsters(void)
}
}
}
pathfinder_cleanup();
}

View File

@ -871,16 +871,20 @@ static void
rp_battles(FILE * F, faction * f)
{
if (f->battles!=NULL) {
struct bmsg * bm;
rnl(F);
centre(F, LOC(f->locale, "section_battle"), false);
rnl(F);
for (bm=f->battles;bm;bm=bm->next) {
while (f->battles) {
struct bmsg * bm = f->battles;
f->battles = bm->next;
RENDER(f, buf, 80, ("battle::header", "region", bm->r));
rnl(F);
centre(F, buf, true);
rnl(F);
rp_messages(F, bm->msgs, f, 0, true, false);
free_messagelist(bm->msgs);
free(bm);
}
}
}

View File

@ -1416,7 +1416,7 @@ select_opponent(battle * b, troop at, int minrow, int maxrow)
*
* }
*
* cv_kill(fgs); Nicht vergessen
* cv_kill(fgs); free(fgs); Nicht vergessen
*/
cvector *

View File

@ -30,3 +30,29 @@ get_gamedate(int turn, gamedate * gd)
return gd;
}
void
calendar_cleanup(void)
{
int i;
free(agename);
for (i=0;i!=seasons;++i) {
free(seasonnames[i]);
}
free(seasonnames);
for (i=0;i!=months_per_year;++i) {
free(monthnames[i]);
}
free(storms);
free(month_season);
free(monthnames);
for (i=0;i!=weeks_per_month;++i) {
free(weeknames[i]);
free(weeknames2[i]);
}
free(weeknames);
free(weeknames2);
}

View File

@ -1,6 +1,10 @@
#ifndef KRNL_CALENDAR_H
#define KRNL_CALENDAR_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *agename;
extern int first_turn;
extern int first_month;
@ -25,5 +29,9 @@ typedef struct gamedate {
} gamedate;
extern gamedate * get_gamedate(int turn, gamedate * gd);
extern void calendar_cleanup(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -355,6 +355,7 @@ sp_combatrosthauch(fighter * fi, int level, double power, spell * sp)
}
}
cv_kill(fgs);
free(fgs);
if (k == 0) {
/* keine Waffen mehr da, die zerstört werden könnten */
@ -678,6 +679,7 @@ sp_immolation(fighter * fi, int level, double power, spell * sp)
if (force==0) break;
}
cv_kill(fgs);
free(fgs);
sprintf(buf, "%d Personen %s getötet",
killed, killed == 1 ? "wurde" : "wurden");
@ -968,6 +970,7 @@ sp_chaosrow(fighter * fi, int level, double power, spell * sp)
power = max(0, power-n);
}
cv_kill(fgs);
free(fgs);
scat("Ein plötzlicher Tumult entsteht");
if (k > 0) {
@ -1045,6 +1048,7 @@ sp_flee(fighter * fi, int level, double power, spell * sp)
}
}
cv_kill(fgs);
free(fgs);
sprintf(buf, "%d Krieger %s von Furcht gepackt.", panik,
panik == 1 ? "wurde" : "wurden");
@ -1672,6 +1676,7 @@ sp_healing(fighter * fi, int level, double power, spell * sp)
j += heal_fighters(fgs, &healhp, false);
j += heal_fighters(fgs, &healhp, true);
cv_kill(fgs);
free(fgs);
if (j == 0) {
scat(", doch niemand mußte magisch geheilt werden.");
@ -1754,6 +1759,7 @@ sp_undeadhero(fighter * fi, int level, double power, spell * sp)
}
}
cv_kill(fgs);
free(fgs);
if (undead == 0) {
sprintf(buf, "%s kann keine Untoten rufen.", unitname(mage));

View File

@ -3032,7 +3032,7 @@ void
add_income(unit * u, int type, int want, int qty)
{
if (want==INT_MAX) want = qty;
add_message(&u->faction->msgs, new_message(u->faction, "income%u:unit%r:region%i:mode%i:wanted%i:amount",
ADDMSG(&u->faction->msgs, msg_message("income", "unit region mode wanted amount",
u, u->region, type, want, qty));
}

View File

@ -378,7 +378,7 @@ cmistake(const unit * u, struct order *ord, int mno, int mtype)
if (u->faction->no == MONSTER_FACTION) return;
sprintf(ebuf, "error%d", mno);
ADDMSG(&u->faction->msgs, msg_message(ebuf,
"command unit region", copy_order(ord), u, u->region));
"command unit region", ord, u, u->region));
}
extern unsigned int new_hashstring(const char* s);

View File

@ -1786,6 +1786,7 @@ run_to(unit * u, region * to)
region_list * route = NULL;
add_regionlist(&route, to);
travel_route(u, route, NULL, NULL, TRAVEL_RUNNING);
free_regionlist(route);
/* weder transport noch follow */
}

View File

@ -58,6 +58,16 @@ typedef struct node {
static node * node_garbage;
void
pathfinder_cleanup(void)
{
while (node_garbage) {
node * n = node_garbage;
node_garbage = n->next;
free(n);
}
}
static node *
new_node(region * r, int distance, node * prev)
{

View File

@ -29,6 +29,9 @@ extern boolean allowed_swim(const struct region * src, const struct region * tar
extern boolean allowed_fly(const struct region * src, const struct region * target);
extern boolean allowed_walk(const struct region * src, const struct region * target);
extern struct region_list * regions_in_range(struct region * src, int maxdist, boolean (*allowed)(const struct region*, const struct region*));
extern void pathfinder_cleanup(void);
#ifdef __cplusplus
}
#endif

View File

@ -821,6 +821,13 @@ free_region(region * r)
r->resources = res->next;
free(res);
}
while (r->donations) {
donation * don = r->donations;
r->donations = don->next;
free(don);
}
free(r);
}

View File

@ -82,6 +82,12 @@ typedef struct land_region {
#endif
} land_region;
typedef struct donation {
struct donation *next;
struct faction *f1, *f2;
int amount;
} donation;
typedef struct region {
struct region *next;
struct land_region *land;

View File

@ -1122,6 +1122,11 @@ stripunit(unit * u)
u->items = it;
}
while (u->attribs) a_remove (&u->attribs, u->attribs);
while (u->reservations) {
struct reservation *res = u->reservations;
u->reservations = res->next;
free(res);
}
}

View File

@ -64,6 +64,7 @@
/* kernel includes */
#include <kernel/border.h>
#include <kernel/building.h>
#include <kernel/calendar.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/message.h>
@ -431,6 +432,7 @@ game_done(void)
creport_cleanup();
report_cleanup();
calendar_cleanup();
}
#endif