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

View file

@ -3184,6 +3184,7 @@ static void
free_side(side * si) free_side(side * si)
{ {
cv_kill(&si->fighters); cv_kill(&si->fighters);
cv_kill(&si->leader.fighters);
} }
static void static void
@ -3228,6 +3229,7 @@ free_battle(battle * b)
} }
cv_next(side); cv_next(side);
cv_kill(&b->sides); cv_kill(&b->sides);
cv_kill(&b->leaders);
cv_foreach(fighter, b->fighters) { cv_foreach(fighter, b->fighters) {
free_fighter(fighter); free_fighter(fighter);
free(fighter); free(fighter);

View file

@ -511,9 +511,6 @@ 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. */ /* Stattdessen nur aus Liste entfernen, aber im Speicher halten. */
choplist(&b->region->buildings, b); choplist(&b->region->buildings, b);
handle_event(&b->attribs, "destroy", b); handle_event(&b->attribs, "destroy", b);

View file

@ -693,9 +693,10 @@ stripfaction (faction * f)
/* TODO: inhalt auch löschen */ /* TODO: inhalt auch löschen */
if (f->msgs) free_messagelist(f->msgs); if (f->msgs) free_messagelist(f->msgs);
while (f->battles) { while (f->battles) {
struct bmsg * b = f->battles; struct bmsg * bm = f->battles;
f->battles = b->next; f->battles = bm->next;
if (b->msgs) free_messagelist(b->msgs); if (bm->msgs) free_messagelist(bm->msgs);
free(bm);
} }
freelist(f->allies); 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) { else if (!u2 || u2->faction!=u->faction) {
assert(rtype); assert(rtype);
add_message(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_message("give", "unit target resource amount", msg_message("give", "unit target resource amount",
u, u2?ucansee(u->faction, u2, u_unknown()):u_peasants(), rtype, n)); u, u2?ucansee(u->faction, u2, u_unknown()):u_peasants(), rtype, n));
if (u2) { if (u2) {
add_message(&u2->faction->msgs, ADDMSG(&u2->faction->msgs,
msg_message("give", "unit target resource amount", msg_message("give", "unit target resource amount",
ucansee(u2->faction, u, u_unknown()), u2, rtype, n)); ucansee(u2->faction, u, u_unknown()), u2, rtype, n));
} }

View file

@ -336,15 +336,12 @@ create_mage(unit * u, magic_t mtyp)
sc_mage *mage; sc_mage *mage;
attrib *a; attrib *a;
#ifndef NDEBUG
a = a_find(u->attribs, &at_mage); a = a_find(u->attribs, &at_mage);
if (a==NULL) { assert(a==NULL);
#endif
a = a_add(&u->attribs, a_new(&at_mage)); a = a_add(&u->attribs, a_new(&at_mage));
mage = calloc(1, sizeof(sc_mage));
a->data.v = mage;
} else {
mage = a->data.v; mage = a->data.v;
memset(mage, 0, sizeof(sc_mage));
}
mage->magietyp = mtyp; mage->magietyp = mtyp;
createspelllist(u, 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->number = itemanz;
res->type = rtype; res->type = rtype;
res->next = reslist; res->next = reslist;
reslist = res->next; reslist = res;
} }
} }
} }

View file

@ -977,13 +977,18 @@ readunit(FILE * F)
rs(F, buf); rs(F, buf);
space = strchr(buf, ' '); space = strchr(buf, ' ');
while (space!=NULL) { if (space!=NULL) {
strcpy(space, space+1); char * inc = space+1;
space=strchr(space, ' '); 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); u->race = rc_find(buf);
assert(u->race); assert(u->race);
rs(F, buf); rs(F, buf);

View file

@ -134,7 +134,7 @@ distribute_items(unit * u)
if (u->items==NULL) return; 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)) { if (alliedunit(u, au->faction, HELP_MONEY) && alliedunit(au, f, HELP_GIVE)) {
struct friend * nf, ** fr = &friends; struct friend * nf, ** fr = &friends;
@ -153,9 +153,9 @@ distribute_items(unit * u)
} }
} }
if (friends && number) { if (friends) {
while (friends) {
struct friend * nf = friends; struct friend * nf = friends;
while (nf) {
unit * u2 = nf->unit; unit * u2 = nf->unit;
item * itm = u->items; item * itm = u->items;
while (itm!=NULL) { while (itm!=NULL) {
@ -170,9 +170,8 @@ distribute_items(unit * u)
itm = itn; itm = itn;
} }
number -= nf->number; number -= nf->number;
nf = nf->next; friends = nf->next;
free(friends); free(nf);
friends = nf;
} }
friends = NULL; friends = NULL;
} }

View file

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