forked from github/server
- lots of memory leaks fixed.
This commit is contained in:
parent
b524e7e392
commit
b0e5f436cd
10 changed files with 125 additions and 126 deletions
|
@ -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;
|
||||
|
|
|
@ -3184,6 +3184,7 @@ static void
|
|||
free_side(side * si)
|
||||
{
|
||||
cv_kill(&si->fighters);
|
||||
cv_kill(&si->leader.fighters);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3228,6 +3229,7 @@ free_battle(battle * b)
|
|||
}
|
||||
cv_next(side);
|
||||
cv_kill(&b->sides);
|
||||
cv_kill(&b->leaders);
|
||||
cv_foreach(fighter, b->fighters) {
|
||||
free_fighter(fighter);
|
||||
free(fighter);
|
||||
|
|
|
@ -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. */
|
||||
choplist(&b->region->buildings, b);
|
||||
handle_event(&b->attribs, "destroy", b);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
assert(a==NULL);
|
||||
#endif
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
if (friends) {
|
||||
while (friends) {
|
||||
struct friend * nf = friends;
|
||||
while (nf) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue