Re: if (blah) ...

From: Chris Proctor (cjp@minotaur.labyrinth.net.au)
Date: 08/19/99


At 05:45  19/08/99 -0700, you wrote:
>"Daniel A. Koepke" wrote:
>
>> On Aug 18, Chris Proctor spake to the list:
>>
>> > Can you then:
>> > free(blah);
>> > blah = NULL;
>> > if (blah) printf("This is still printed.\n");
>> > ?
>>
>> Yes, you can, and, in fact, it's done throughout the CircleMUD code.
>> Several instances can be found just in the nanny() function.
>
>Really?  Could you please point out one single instance where this is
>done in nanny?  I looked and could not find even one of the "several"
>instances you mention.

Having had a look myself, and in relation to my question (which was really
"Is it safe to set a pointer equal to null after freeing it") dak is
certainly correct.
This was from bpl15 (didn't bother checking whatever archaic version I'm on).
Obviously it doesn't set the pointer equal to null and then do an if
(pointer) on it immediately (that'd be a bit silly, wouldn't it?).
Not sure exactly which bit you were referring to there . . .

from nanny(), in interpreter.c

        if (PLR_FLAGGED(d->character, PLR_DELETED)) {
          /* We get a false positive from the original deleted character. */
          free_char(d->character);
          d->character = NULL;

and a bit lower down:
    } else if (*arg == 'n' || *arg == 'N') {
      SEND_TO_Q("Okay, what IS it, then? ", d);
      free(d->character->player.name);
      d->character->player.name = NULL;

and again:
    case '2':
      if (d->character->player.description) {
        SEND_TO_Q("Old description:\r\n", d);
        SEND_TO_Q(d->character->player.description, d);
        free(d->character->player.description);
        d->character->player.description = NULL;
      }

regards,

Chris
Regards,
Chris Proctor
------------------------------------------------------------------------
Chris Proctor, Technical Support
Labyrinth Connections Pty Ltd
E-mail: support2@labyrinth.net.au
Phone: +61 3 9642 4222 Fax: +61 3 9642 4955
Online Support Database: http://notes.labyrinth.net.au
------------------------------------------------------------------------


     +------------------------------------------------------------+
     | 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