Re: [CODE] crash-bug with medit on pl21-dg8-oasis201

From: Thomas Arp (t_arp@stofanet.dk)
Date: 09/30/02


From: "Ronald Evers" <dlanor@xs4all.nl>
> Hey folks,
>
> I've found a bug in medit that I can't seem to fix. Whenever I
> alter a mob that has a script set I get a seg fault when I exit
> the medit menu and save it.
>
> I'm using bpl21 with this dg_scripts_pl8_with_oasis_bpl21.patch
> patch from the ftp site installed.
>
> The mob I tried this on was the wandering spirit (1202). I gave
> him one trigger (greet) that simply makes him say hi. Then just
> "medit 1202;l;0;q;y" and there's your seg fault..
>

Change your free_mobile() to look like this:
/*
 * Free a mobile structure that has been edited.
 * Take care of existing mobiles and their mob_proto!
 */
int free_mobile(struct char_data *mob)
{
  int i;

  if (mob == NULL)
    return FALSE;

  /*
   * Non-prototyped mobile.  Also known as new mobiles.
   */
  if ((i = GET_MOB_RNUM(mob)) == NOBODY) {
    free_mobile_strings(mob);
    free_proto_script(mob, MOB_TRIGGER);
  } else { /* Prototyped mobile. */
    if (mob->player.name && mob->player.name != mob_proto[i].player.name)
      free(mob->player.name);
    if (mob->player.title && mob->player.title != mob_proto[i].player.title)
      free(mob->player.title);
    if (mob->player.short_descr && mob->player.short_descr !=
mob_proto[i].player.short_descr)
      free(mob->player.short_descr);
    if (mob->player.long_descr && mob->player.long_descr !=
mob_proto[i].player.long_descr)
      free(mob->player.long_descr);
    if (mob->player.description && mob->player.description !=
mob_proto[i].player.description)
      free(mob->player.description);
    /*[1]*/
    if (mob->proto_script && mob->proto_script != mob_proto[i].proto_script)
      free_proto_script(mob, MOB_TRIGGER);
  }
  while (mob->affected)
    affect_remove(mob, mob->affected);


  free(mob);
  return TRUE;
}

I made buggy code in the first place, by having the check at [1] below
the code where i is sure to have meaning. This causes strange behaviour
and occasional crashes.

Also, remember to add the line

  OLC_MOB(d)->proto_script = OLC_SCRIPT(d);

in medit_save_internally(), to make your changes show in medit.

I'll have pl9 out within a week - at most 10 days. Got swamped with work,
and had to postpone the deadline.


Welcor

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT