Re: [BUG]Bug in stock do_quit

From: Peter Ajamian (
Date: 01/01/01

George Greer wrote:
> On Mon, 1 Jan 2001, Peter Ajamian wrote:
> >extract_char calls free_char(ch) which in turn calls free(ch).
> >
> >after ch has been freed you are referencing it (an invalid area of
> >memory) in save_char.
> You traced the mobile path.  That doesn't occur from do_quit.

Hrmmm, right, this is what was throwing me off...

  } else {  /* if a player gets purged from within the game */
    if (!freed)

I guess, though that if they were purged it wouldn't be called via
do_quit either.

Still, though, it occurred to me that this sort of thing has in the past
caused problems with various different patches and snippets (most
notably DG Scripts trying to reference a mob after it has been freed).
It occurred to me that this could most likely be prevented if the
freeing up of the character structure were delayed for a relatively
short period of time, sort of a delayed clean-up.  Something like that
could easily be accomplished by doing something like the following...

You could rename free_char to real_free_char then do the following...

new global in db.c, struct char_data *junk_char_list = NULL;

then new function free_char...

void free_char(struct char_data *ch)
  ch->next = junk_char_list;
  junk_char_list = ch;

Then somewhere in game_loop...

struct char_data *tch;

/* ... */

while (junk_char_list) {
  tch = junk_char_list;
  junk_char_list = tch->next;

This would have the effect of postponing the freeing up of the char_data
struct until it is no longer needed.

Regards, Peter

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/03/01 PST