[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  Compiling the server
. . -> [Subject]  Log: STRFREE called on str_dup pointer:
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Log: STRFREE called on str_dup pointer:

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Robert Powell   Australia  (367 posts)  [Biography] bio
Date Wed 11 Jun 2014 11:03 AM (UTC)
Message
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,

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 11 Jun 2014 08:12 PM (UTC)
Message
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   *
 ****************************************************************************/

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Robert Powell   Australia  (367 posts)  [Biography] bio
Date Reply #2 on Wed 11 Jun 2014 09:18 PM (UTC)
Message
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);

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 12 Jun 2014 04:09 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


2,918 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]