- 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

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

View file

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

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

@ -187,7 +187,7 @@ extern int dice(int count, int value);
static void static void
init_mage(attrib * a) { init_mage(attrib * a) {
a->data.v = calloc(sizeof(sc_mage), 1); a->data.v = calloc(sizeof(sc_mage), 1);
} }
static void static void
@ -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);
a = a_add(&u->attribs, a_new(&at_mage)); #endif
mage = calloc(1, sizeof(sc_mage)); a = a_add(&u->attribs, a_new(&at_mage));
a->data.v = mage; mage = a->data.v;
} else {
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

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

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) {
struct friend * nf = friends; while (friends) {
while (nf) { struct friend * nf = friends;
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;
} }
@ -1197,18 +1196,18 @@ invisible(const unit *target, const unit * viewer)
void void
stripunit(unit * u) stripunit(unit * u)
{ {
free(u->name); free(u->name);
free(u->display); free(u->display);
free_order(u->thisorder); 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) {
item * it = u->items->next; item * it = u->items->next;
u->items->next = NULL; u->items->next = NULL;
i_free(u->items); i_free(u->items);
u->items = it; u->items = it;
} }
while (u->attribs) a_remove (&u->attribs, u->attribs); while (u->attribs) a_remove (&u->attribs, u->attribs);
while (u->reservations) { while (u->reservations) {
struct reservation *res = u->reservations; struct reservation *res = u->reservations;
u->reservations = res->next; u->reservations = res->next;

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 */