Re: [CODE][BUGGY CODE :P][OBJPURGE ------[fixed]

From: Ron Cole (rcole@ezy.net)
Date: 01/13/99


>PCOMM(do_purge_obj) {
>  OBJECT *i;

   OBJECT *i, *next;

>  int number, r_num;
>  bool found = FALSE;
>
>  one_argument(argument, arg);
>
>  if(!*arg) {
>    send_to_char("I need an object to purge.\n\r", ch);
>    return;
>  }
>
>  if (!isdigit(*arg)) {
>    send_to_char("Usage: objpurge [vnum]\r\n", ch);
>    return;
>  }
>
>  if ( (number = atoi(arg)) < 0) {
>    send_to_char("A NEGATIVE number??\r\n", ch);
>    return;
>  }
>
>  for (i = object_list; i; i = i->next) {

   for (i = object_list; i; i = next) {
     next = i->next;

>    if (GET_OBJ_VNUM(i) != number)
>      continue;
>    if (i->carried_by)
>      act("$p burns into fine ashes and slips through your fingers.",
>           FALSE, i->carried_by, i, 0, TO_CHAR);
>    if ((i->in_room != NOWHERE) &&
>        (world[i->in_room].people)) {
>      act("$p is burned into fine ashes and slips through $n's
>fingers.",
>           TRUE, world[i->in_room].people, i, 0, TO_ROOM);
>      act("$p is burned into fine ashes and slips through your
>fingers.",
>           TRUE, world[i->in_room].people, i, 0, TO_CHAR);
>    }
>    if (i->worn_by) {
>      act("$p burns into fine ashes and is taken by the breeze.",
>           FALSE, i->worn_by, i, 0, TO_CHAR);
>      act("Your $p burns into fine ashes and is taken by the breeze.",
>           FALSE, i->worn_by, i, 0, TO_ROOM);
>    }
>
>    extract_obj(i);
>    found = TRUE;
>  }
>  if (found) {
>    sprintf(buf, "%s objpurges all objects with vnum %d",
>            GET_NAME(ch), number);
>    mudlog(buf, BRF, LVL_GRGOD, TRUE);
>  }
>}

The command will run as is in some environments, but on a busy machine,
there's a good chance of a crash.  When you extract the object, the memory is
freed.  At the top of the loop, when you get the next object, you are
accessing freed memory, which could have been changed, either by any code
after the extract, or by other jobs in the system.

Ron


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



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