void affect_to_char( CHAR_DATA *ch, AFFECT_DATA *paf )
{
AFFECT_DATA *paf_new;
if ( affect_free == NULL )
{
paf_new = alloc_perm( sizeof(*paf_new) );
}
else
{
paf_new = affect_free;
affect_free = affect_free->next;
}
*paf_new = *paf;
paf_new->next = ch->affected;
ch->affected = paf_new;
affect_modify( ch, paf_new, TRUE);
return;
}
void spell_fly( int sn, int level, CHAR_DATA *ch, void *vo )
{
CHAR_DATA *victim = (CHAR_DATA *) vo;
AFFECT_DATA af;
if ( IS_AFFECTED(victim, AFF_FLYING) )
return;
af.type = sn;
af.duration = level + 3;
af.location = 0;
af.modifier = 0;
af.bitvector = AFF_FLYING;
affect_to_char( victim, &af );
send_to_char( "You rise up off the ground.\n\r", victim );
act( "$n rises up off the ground.", victim, NULL, NULL, TO_ROOM );
return;
}
My problem is with alloc_perm() and the block lists it uses. I don't believe the lists for data like affects are being utilized properly or such.
If I cast a spell on myself, say, fly, then check memory stats I notice my perm block usage has gone up by 1 and a few bytes of total memory. Casting a second spell, sanctuary, yields the same results. However, if I use dispel magic which just recursively calls affect_remove(), perm block usage either INCREASES or stays the same. However if it stays the same, I should be able to re-cast the same spells and it should use already alloc'ed memory, correct? But each time it re-allocs more.
After the game has been running for a day or so, and memory usage is upwards of 20mb, sometimes characters seem to corrupt. Most notably people's ch->home for recall, is an int. It will randomly change to some value between 1 and 10. I've checked every place in the code that references that, and nowhere explicitly sets it except to initialize it in load_char_obj(), read it in do_recall(), or change if a player chooses to with do_home(). Values in some people's ch->pcdata structs are sometimes changing too, and I can't ever reproduce it. A value is there then suddenly it is zeroed out.
I really don't know if I described that very well as it's easy for me to what what happens in my game but hard to describe it =\.
This is based on a flavor of God Wars, but I believe all the memory management is still the same as stock Merc.
Any help, or even a nudge in the right direction, would be appreciated! I run this all on my own in-home Debian box, so any different debugging tools, libs, etc, are no problem to get. I just want to try to find a resolution :(