BUG: Freeing null pointer

Posted by Robert Powell on Sun 19 Jun 2005 10:18 AM — 2 posts, 12,192 views.

Australia #0
Every now and again i have been getting the following bugs warnings popping up,
Log: [*****] BUG: Freeing null pointer questing.c:942
Log: [*****] BUG: Freeing null pointer questing.c:943

which is the 2 strfree's in the fragment below,


else if (xIS_SET(ch->act,PLR_QUESTOR))
        {
          if (--ch->pcdata->countdown <= 0)
            {
              char buf [MAX_STRING_LENGTH];

              ch->pcdata->nextquest = 5;
              sprintf(buf, "You have run out of time for your quest!\n\rYou may quest again in %d minutes.\n\r",ch->pcdata->nextquest);
              send_to_char(buf, ch);
              xREMOVE_BIT(ch->act, PLR_QUESTOR);
              STRFREE(ch->pcdata->questroom);
              STRFREE(ch->pcdata->questarea);
              ch->pcdata->questgiver = NULL;
              ch->pcdata->countdown = 0;
              ch->pcdata->questmob = 0;
            }
          if (ch->pcdata->countdown > 0 && ch->pcdata->countdown < 3)
            {
              send_to_char("Better hurry, you're almost out of time for your quest!\n\r",ch);
              return;
            }
        }


Now i understand that the value of questroom and questarea are null, but i cannot work out how come, Should i just check for null and if so assign it a value to free, or is it safe to just the code clean it up, or is there something more wicked going on here that i need to attand too.

Oh also this is the Aurora quest code if that helps any.

Thanks in advance.
Canada #1
It's nothing serious in the current form. The fact that it is giving you the log error make it safe, but coule be annpoying. If you just wanted to eliminate the log errors you could: a) Add a
if ( ch->pcdata->questroom )
STRFREE(ch->pcdata->questroom);
This is how it should be done to be safe, and it will clear up your warnings. b) It also duplicates some code, since in STRFREE it has the same check. You could also remove the log message in STRFREE, though I don't recommend this as the log message is useful if there is actually something missing, which may be the case with you.

The fact that both variable are not set could certainly cause issues with the code if they are ever referenced. I would try to find out why they are not being set(presumably when the quest begins? I'm unfamiliar with the code snippet) and correct the issue at the source, as this would also fix the issue. If they are not always set and don't always need to be, the if check above the STRFREE is probably the safest bet.