Oh man is this a bad one...

From: Hades (tourach@servtech.com)
Date: 05/08/96


extract_char(ch)... in there it calls free_char(ch), which SHOULD free all
memory used by a char, right? Then it frees the ch itself with free(ch) then
ch = NULL; right?

SO when it returns from free_char, ch SHOUDL = NULL, right?

SO when it returns from extract_char, ch should be null, right?

WELL... it's not getting set to null. If I set a static pointer to a char,
extract it, free it, set it = NULL in free_char, and 5 mins later I try to
see the nam eof that freed char with a command I made, teh entire fucking
mob is still in memory... did I fuck something up that would prevent it from
freeing the ch correctly?

What I really dont undertsnad is this... at the end of free_char, it sets ch
= NULL, but in extract char I have:
if(ch)
  mudlog("x", 2, 32, 0);

right after it retuns from free_char... and it DOES mudlog x every time it
calls extract_char... even though ch = NULL before it retuns (and I checked,
the code IS making it that far) it's NOT getting returned... is there some
funky compiler option I screwed up that's causing this? free(ch); ch = NULL;
should wie the char, but like I said before, 5 mins later when I sue the
static pointer to where the ch was before I freed it, it's NOT null... the
damn thing is still there in memory. Or hell... it could at least crash
because it's crap in memory.

This is REALLY bugging the crap out of me... ANYONE have any ideas?

Here's my free_char if it matters:

void free_char(struct char_data *ch)
{
  int i;
  struct afk_rec *afk, *temp;
  struct alias *a;
  struct char_data *mob;

  void free_alias(struct alias *a);

  if (ch->player_specials != NULL && ch->player_specials != &dummy_mob) {
    if (ch->player_specials->poofin)
      free(ch->player_specials->poofin);
    if (ch->player_specials->poofout)
      free(ch->player_specials->poofout);
    while ((a = GET_ALIASES(ch)) != NULL) {
      GET_ALIASES(ch) = (GET_ALIASES(ch))->next;
      free_alias(a);
    }
    while (ch->player_specials->afk) {
      afk = ch->player_specials->afk;
      if (ch->player_specials->afk->name)
	free(ch->player_specials->afk->name);
      if (ch->player_specials->afk->msg)
	free(ch->player_specials->afk->msg);
      REMOVE_FROM_LIST(afk, ch->player_specials->afk, next);
    }
    free(ch->player_specials);
    if (IS_NPC(ch))
      mlog("SYSERR: Mob had player_specials allocated!");
  }

  if (!IS_NPC(ch) || (IS_NPC(ch) && GET_MOB_RNUM(ch) == -1)) {
    /* if this is a player, or a non-prottyped non-player, free all */
    if (ch->player.name)
      free(ch->player.name);
    if (ch->player.short_descr)
      free(ch->player.short_descr);
    if (ch->player.title)
      free(ch->player.title);
    if (ch->player.long_descr)
      free(ch->player.long_descr);
    if (ch->player.description)
      free(ch->player.description);
    if (ch->player.afkmsg)
      free(ch->player.afkmsg);
    if (!IS_NPC(ch) && ch->player.prompt)
      free(ch->player.prompt);
    if(!IS_NPC(ch) && ch->player_specials->last_killed_by.name)
      free(ch->player_specials->last_killed_by.name);
  }
  else if ((i = GET_MOB_VNUM(ch)) > -1) {
    mob = find_mob(i);
    /* otherwise, free strings only if the string is not pointing at prot */
    if (ch->player.name && ch->player.name != mob->player.name)
      free(ch->player.name);
    if (ch->player.short_descr && ch->player.short_descr != mob->player.short_descr)
      free(ch->player.short_descr);
    if (ch->player.title && ch->player.title != mob->player.title)
      free(ch->player.title);
    if (ch->player.long_descr && ch->player.long_descr != mob->player.long_descr)
      free(ch->player.long_descr);
    if (ch->player.description && ch->player.description != mob->player.description)
      free(ch->player.description);
    if (ch->player.afkmsg && ch->player.afkmsg != mob->player.afkmsg)
      free(ch->player.afkmsg);
    if (ch->player.prompt && ch->player.prompt != mob->player.prompt)
      free(ch->player.prompt);
  }
  while (ch->affected)
    affect_remove(ch, ch->affected);

  free(ch);
  ch = NULL;
}

Those last 2 lines should kill the char outta memory, even if it leaves the
strings and such, right? Well.. I dunno... any help appreiciated.



This archive was generated by hypermail 2b30 : 12/18/00 PST