Log: STRFREE called on str_dup pointer:

Posted by Robert Powell on Wed 11 Jun 2014 11:03 AM — 4 posts, 21,248 views.

Australia #0
Log: STRFREE called on str_dup pointer: quest.c, line 961

In mud.h pcdata


const char * questarea; /* Questmaster */
const char * questroom; /* Questmaster */


In quest.c update function


if ( ch->pcdata->questroom )
   STRFREE ( ch->pcdata->questroom );
if ( ch->pcdata->questarea )
   STRFREE ( ch->pcdata->questarea );


Can anyone tell me what is going on here,
Australia Forum Administrator #1
Judging by the source, if you call str_alloc (STRALLOC) to duplicate a string you must call DISPOSE to get rid of it, and not STRFREE.

See this comment at the start of hashstr.c:


/****************************************************************************
 * Advanced string hashing functions (c)1996 D.S.D. Software, written by    *
 * Derek Snider for use in SMAUG.                                           *
 *                                                                          *
 * These functions keep track of how many "links" are pointing to the	    *
 * memory allocated, and will free the memory if all the links are removed. *
 * Make absolutely sure you do not mix use of strdup and free with these    *
 * functions, or nasty stuff will happen!                                   *
 * Most occurances of strdup/str_dup should be replaced with str_alloc, and *
 * any free/DISPOSE used on the same pointer should be replaced with	    *
 * str_free.  If a function uses strdup for temporary use... it is best if  *
 * it is left as is.  Just don't get usage mixed up between conventions.    *
 * The hashstr_data size is 8 bytes of overhead.  Don't be concerned about  *
 * this as you still save lots of space on duplicate strings.	-Thoric   *
 ****************************************************************************/
Australia #2
I did try dispose but that also came back with a BUG similar to the other one. So i know there is something wrong somewhere.

DISPOSE called on STRALLOC pointer:

I went looking for where questarea and questroom are given any value and this is the first instance of it that I can find,


ch->pcdata->questroom = room->area->name;
ch->pcdata->questarea = room->name;


So both DISPOSE and STRFREE think that the other guy should be doing the cleaning up.

So what I am guessing I need to do is the following so that the string has been allocated correctly and then the macro will clean things up properly without issuing the bug.


ch->pcdata->questroom = STRALLOC ( room->area->name);
Australia Forum Administrator #3
Quote:


ch->pcdata->questroom = room->area->name;
ch->pcdata->questarea = room->name;



That is just copying the pointer, which is probably not a good idea. Certainly if you just copy the pointer you shouldn't dispose of it at all (you don't "own" it).

Probably you should str_dup it (duplicate the string) and then you own the copy.