- lots of memory leaks fixed.

This commit is contained in:
Enno Rehling 2006-01-29 01:55:36 +00:00
parent b524e7e392
commit b0e5f436cd
10 changed files with 125 additions and 126 deletions

View file

@ -499,7 +499,7 @@ recruit(unit * u, struct order * ord, request ** recruitorders)
if (recruitcost) {
pl = getplane(r);
if (pl && fval(pl, PFL_NORECRUITS)) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "error_pflnorecruit", ""));
return;
}
@ -943,9 +943,8 @@ maintain(building * b, boolean first)
assert(cost==0);
}
} else {
message * msg = add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_message("maintenancefail", "unit building", u, b));
msg_release(msg);
return false;
}
return true;
@ -1214,7 +1213,7 @@ allocate_resource(unit * u, const resource_type * rtype, int want)
&& !alliedunit(u2, u->faction, HELP_GUARD)
&& armedmen(u2)
) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "region_guarded", "guard", u2));
return;
}
@ -1233,7 +1232,7 @@ allocate_resource(unit * u, const resource_type * rtype, int want)
&& u2->number
&& !alliedunit(u2, u->faction, HELP_GUARD))
{
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "region_guarded", "guard", u2));
return;
}
@ -1518,7 +1517,7 @@ split_allocations(region * r)
}
if (al->want==INT_MAX) al->want = al->get;
if (fval(al, AFL_LOWSKILL)) {
add_message(&al->unit->faction->msgs,
ADDMSG(&al->unit->faction->msgs,
msg_message("produce_lowskill", "unit region resource",
al->unit, al->unit->region, rtype));
} else {
@ -1924,7 +1923,7 @@ buy(unit * u, request ** buyorders, struct order * ord)
}
}
if (r_demand(r, ltype)) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "luxury_notsold", ""));
return;
}
@ -2158,7 +2157,7 @@ sell(unit * u, request ** sellorders, struct order * ord)
/* Belagerte Einheiten können nichts verkaufen. */
if (besieged(u)) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "error60", ""));
return false;
}
@ -2327,21 +2326,21 @@ plant(region *r, unit *u, int raw)
skill = eff_skill(u, SK_HERBALISM, r);
itype = rherbtype(r);
if (skill < 6) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 6, itype->rtype, 1));
return;
}
/* Wasser des Lebens prüfen */
if (get_pooled(u, rt_water, GET_DEFAULT) == 0) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "resource_missing", "missing", rt_water));
return;
}
n = get_pooled(u, itype->rtype, GET_DEFAULT);
/* Kräuter prüfen */
if (n==0) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "resource_missing", "missing",
itype->rtype));
return;
@ -2383,13 +2382,13 @@ planttrees(region *r, unit *u, int raw)
/* Skill prüfen */
skill = eff_skill(u, SK_HERBALISM, r);
if (skill < 6) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
return;
}
if (fval(r, RF_MALLORN) && skill < 7 ) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 7, rtype, 1));
return;
@ -2398,7 +2397,7 @@ planttrees(region *r, unit *u, int raw)
n = get_pooled(u, rtype, GET_DEFAULT);
/* Samen prüfen */
if (n==0) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype));
return;
}
@ -2457,7 +2456,7 @@ breedtrees(region *r, unit *u, int raw)
n = get_pooled(u, rtype, GET_DEFAULT);
/* Samen prüfen */
if (n==0) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype));
return;
}
@ -2718,7 +2717,7 @@ steal_cmd(unit * u, struct order * ord, request ** stealorders)
}
if (u2->faction->age < NewbieImmunity()) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "newbie_immunity_error",
"turns", NewbieImmunity()));
return;
@ -2731,7 +2730,7 @@ steal_cmd(unit * u, struct order * ord, request ** stealorders)
assert(u->region==u2->region);
if (!can_contact(r, u, u2)) {
add_message(&u->faction->msgs, msg_feedback(u, ord, "error60", ""));
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error60", ""));
return;
}
@ -3025,7 +3024,7 @@ tax_cmd(unit * u, struct order * ord, request ** taxorders)
u2 = is_guarded(r, u, GUARD_TAX);
if (u2) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "region_guarded", "guard", u2));
return;
}
@ -3135,7 +3134,7 @@ produce(void)
case K_WORK:
if (playerrace(u->race)) work(u, u->thisorder);
else if (playerrace(u->faction->race)) {
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "race_cantwork", "race", u->race));
}
break;

View file

@ -3183,7 +3183,8 @@ make_battle(region * r)
static void
free_side(side * si)
{
cv_kill(&si->fighters);
cv_kill(&si->fighters);
cv_kill(&si->leader.fighters);
}
static void
@ -3205,40 +3206,41 @@ free_fighter(fighter * fig)
static void
free_battle(battle * b)
{
side *side;
fighter *fighter;
meffect *meffect;
int max_fac_no = 0;
if (bdebug) {
fclose(bdebug);
}
while (b->factions) {
side *side;
fighter *fighter;
meffect *meffect;
int max_fac_no = 0;
if (bdebug) {
fclose(bdebug);
}
while (b->factions) {
bfaction * bf = b->factions;
faction * f = bf->faction;
faction * f = bf->faction;
b->factions = bf->next;
max_fac_no = max(max_fac_no, f->no);
max_fac_no = max(max_fac_no, f->no);
free(bf);
}
cv_foreach(side, b->sides) {
free_side(side);
free(side);
}
cv_next(side);
cv_kill(&b->sides);
cv_foreach(fighter, b->fighters) {
free_fighter(fighter);
free(fighter);
}
cv_next(fighter);
cv_kill(&b->fighters);
cv_foreach(meffect, b->meffects) {
free(meffect);
}
cv_next(meffect);
cv_kill(&b->meffects);
}
cv_foreach(side, b->sides) {
free_side(side);
free(side);
}
cv_next(side);
cv_kill(&b->sides);
cv_kill(&b->leaders);
cv_foreach(fighter, b->fighters) {
free_fighter(fighter);
free(fighter);
}
cv_next(fighter);
cv_kill(&b->fighters);
cv_foreach(meffect, b->meffects) {
free(meffect);
}
cv_next(meffect);
cv_kill(&b->meffects);
}
static int *

View file

@ -481,7 +481,7 @@ new_building(const struct building_type * btype, region * r, const struct locale
void
destroy_building(building * b)
{
unit *u;
unit *u;
direction_t d;
static const struct building_type * bt_caravan, * bt_dam, * bt_tunnel;
boolean init = false;
@ -493,15 +493,15 @@ destroy_building(building * b)
bt_tunnel = bt_find("tunnel");
}
if (!bfindhash(b->no)) return;
for (u=b->region->units; u; u=u->next) {
if (u->building == b) leave(b->region, u);
}
b->size = 0;
update_lighthouse(b);
bunhash(b);
if (!bfindhash(b->no)) return;
for (u=b->region->units; u; u=u->next) {
if (u->building == b) leave(b->region, u);
}
b->size = 0;
update_lighthouse(b);
bunhash(b);
/* Falls Karawanserei, Damm oder Tunnel einstürzen, wird die schon
* gebaute Straße zur Hälfte vernichtet */
if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) {
@ -511,12 +511,9 @@ destroy_building(building * b)
}
}
#if 0 /* TODO: Memoryleak. Aber ohne klappt das Rendern nicht! */
removelist(&b->region->buildings, b);
#endif
/* Stattdessen nur aus Liste entfernen, aber im Speicher halten. */
choplist(&b->region->buildings, b);
handle_event(&b->attribs, "destroy", b);
/* Stattdessen nur aus Liste entfernen, aber im Speicher halten. */
choplist(&b->region->buildings, b);
handle_event(&b->attribs, "destroy", b);
}
extern attrib_type at_icastle;

View file

@ -693,9 +693,10 @@ stripfaction (faction * f)
/* TODO: inhalt auch löschen */
if (f->msgs) free_messagelist(f->msgs);
while (f->battles) {
struct bmsg * b = f->battles;
f->battles = b->next;
if (b->msgs) free_messagelist(b->msgs);
struct bmsg * bm = f->battles;
f->battles = bm->next;
if (bm->msgs) free_messagelist(bm->msgs);
free(bm);
}
freelist(f->allies);

View file

@ -66,11 +66,11 @@ add_give(unit * u, unit * u2, int n, const resource_type * rtype, struct order *
}
else if (!u2 || u2->faction!=u->faction) {
assert(rtype);
add_message(&u->faction->msgs,
ADDMSG(&u->faction->msgs,
msg_message("give", "unit target resource amount",
u, u2?ucansee(u->faction, u2, u_unknown()):u_peasants(), rtype, n));
if (u2) {
add_message(&u2->faction->msgs,
ADDMSG(&u2->faction->msgs,
msg_message("give", "unit target resource amount",
ucansee(u2->faction, u, u_unknown()), u2, rtype, n));
}

View file

@ -187,7 +187,7 @@ extern int dice(int count, int value);
static void
init_mage(attrib * a) {
a->data.v = calloc(sizeof(sc_mage), 1);
a->data.v = calloc(sizeof(sc_mage), 1);
}
static void
@ -336,15 +336,12 @@ create_mage(unit * u, magic_t mtyp)
sc_mage *mage;
attrib *a;
#ifndef NDEBUG
a = a_find(u->attribs, &at_mage);
if (a==NULL) {
a = a_add(&u->attribs, a_new(&at_mage));
mage = calloc(1, sizeof(sc_mage));
a->data.v = mage;
} else {
mage = a->data.v;
memset(mage, 0, sizeof(sc_mage));
}
assert(a==NULL);
#endif
a = a_add(&u->attribs, a_new(&at_mage));
mage = a->data.v;
mage->magietyp = mtyp;
createspelllist(u, mtyp);
@ -966,7 +963,7 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord)
res->number = itemanz;
res->type = rtype;
res->next = reslist;
reslist = res->next;
reslist = res;
}
}
}

View file

@ -164,27 +164,27 @@ message *
msg_message(const char * name, const char* sig, ...)
/* msg_message("oops_error", "unit region command", u, r, cmd) */
{
va_list marker;
const message_type * mtype = mt_find(name);
char paramname[64];
const char *ic = sig;
variant args[16];
memset(args, 0, sizeof(args));
if (!mtype) {
log_warning(("trying to create message of unknown type \"%s\"\n", name));
return NULL;
}
va_start(marker, sig);
while (*ic && !isalnum(*ic)) ic++;
while (*ic) {
char * oc = paramname;
va_list marker;
const message_type * mtype = mt_find(name);
char paramname[64];
const char *ic = sig;
variant args[16];
memset(args, 0, sizeof(args));
if (!mtype) {
log_warning(("trying to create message of unknown type \"%s\"\n", name));
return NULL;
}
va_start(marker, sig);
while (*ic && !isalnum(*ic)) ic++;
while (*ic) {
char * oc = paramname;
int i;
while (isalnum(*ic)) *oc++ = *ic++;
*oc = '\0';
*oc = '\0';
for (i=0;i!=mtype->nparameters;++i) {
if (!strcmp(paramname, mtype->pnames[i])) break;
}

View file

@ -977,13 +977,18 @@ readunit(FILE * F)
rs(F, buf);
space = strchr(buf, ' ');
while (space!=NULL) {
strcpy(space, space+1);
space=strchr(space, ' ');
if (space!=NULL) {
char * inc = space+1;
char * outc = space;
do {
while (*inc==' ') ++inc;
while (*inc) {
*outc++ = *inc++;
if (*inc==' ') break;
}
} while (*inc);
*outc = 0;
}
/* if (strcmp(buf, "giant turtle")==0) strcpy(buf, "giantturtle");
if (strcmp(buf, "young dragon")==0) strcpy(buf, "youngdragon");
if (strcmp(buf, "young dragon")==0) strcpy(buf, "youngdragon"); */
u->race = rc_find(buf);
assert(u->race);
rs(F, buf);

View file

@ -134,7 +134,7 @@ distribute_items(unit * u)
if (u->items==NULL) return;
for (au=r->units;au;au=au->next) if (au->faction!=f) {
for (au=r->units;au;au=au->next) if (au->faction!=f && au->number>0) {
if (alliedunit(u, au->faction, HELP_MONEY) && alliedunit(au, f, HELP_GIVE)) {
struct friend * nf, ** fr = &friends;
@ -153,9 +153,9 @@ distribute_items(unit * u)
}
}
if (friends && number) {
struct friend * nf = friends;
while (nf) {
if (friends) {
while (friends) {
struct friend * nf = friends;
unit * u2 = nf->unit;
item * itm = u->items;
while (itm!=NULL) {
@ -170,9 +170,8 @@ distribute_items(unit * u)
itm = itn;
}
number -= nf->number;
nf = nf->next;
free(friends);
friends = nf;
friends = nf->next;
free(nf);
}
friends = NULL;
}
@ -1197,18 +1196,18 @@ invisible(const unit *target, const unit * viewer)
void
stripunit(unit * u)
{
free(u->name);
free(u->display);
free(u->name);
free(u->display);
free_order(u->thisorder);
free_orders(&u->orders);
if(u->skills) free(u->skills);
while (u->items) {
item * it = u->items->next;
u->items->next = NULL;
i_free(u->items);
u->items = it;
}
while (u->attribs) a_remove (&u->attribs, u->attribs);
free_orders(&u->orders);
if(u->skills) free(u->skills);
while (u->items) {
item * it = u->items->next;
u->items->next = NULL;
i_free(u->items);
u->items = it;
}
while (u->attribs) a_remove (&u->attribs, u->attribs);
while (u->reservations) {
struct reservation *res = u->reservations;
u->reservations = res->next;

View file

@ -28,7 +28,6 @@
#include <kernel/reports.h>
#include <kernel/save.h>
#include <kernel/skill.h>
#include <kernel/study.h>
#include <kernel/unit.h>
/* util includes */