Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ Running the server ➜ DISPOSE Function in SWR

DISPOSE Function in SWR

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


Posted by KipKerensky   (3 posts)  Bio
Date Sun 09 Nov 2003 02:19 AM (UTC)
Message
I've been trying to fix a bug for the past 4 days or so. On log in, either a new char or old sometimes, It will crash at getting a new password. Using gdb found was caused by DISPOSE in the free_char function. This occurs at both the DISPOSE(ch->pcdata) and DISPOSE(ch). In additiong to this, in clean_obj_queue, if try to eat/sac something that came in after quiting, DISPOSE(obj) does not work. If i comment out these lines the code works fine.

Using cygwin and have tried making sure all pointers are cleared or not. Appreciate any help.

-Kip
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #1 on Sun 09 Nov 2003 09:55 AM (UTC)
Message
These errors can be extremely hard to track down. 99.9% of the time it is due to a mismatched allocation. You STRALLOC and then DISPOSE, resulting in a crash. STRALLOC must always be used with STRFREE, and str_dup must always be used with DISPOSE. Mixing the 2 is a recipe for disaster.

If your host has it installed, Valgrind is generally a great tool for locating things like this. Often it will catch it as it happens and you can then isolate it immediately. But either way it will pinpoint it at the moment your code crashes.
Top

Posted by KipKerensky   (3 posts)  Bio
Date Reply #2 on Sun 09 Nov 2003 08:49 PM (UTC)

Amended on Sun 09 Nov 2003 08:50 PM (UTC) by KipKerensky

Message
Thanks for the help. You were right about the mismatched allocation errors. Took awhile to make sure everything was right.

-Kip
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Sun 09 Nov 2003 09:19 PM (UTC)
Message
This is one advantage of using C++ over C. Using its stronger typing, you can enforce that this kind of thing never happens. If your "hashed string" is a type of its own, then you can't call free on it, and you won't be able to call STR_ALLOC for a normal char *. Personally I find it extremely confusing to mix char* hashed and not hashed, and it's impossible to know which it is without tracing all the way back to the allocation.

So yes, this is one major advantage to using C++, for experienced programmers who care about this sort of thing.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #4 on Sun 09 Nov 2003 11:50 PM (UTC)
Message
Which is one reason why I wanted to have my code compiled as C++ since it caught numerous mistakes I'd made in things just during compile. Fortunately I had the aid of Valgrind to spot the other disasters before I got to the point of using g++ to do my dirty work.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Mon 10 Nov 2003 12:37 AM (UTC)
Message
What exactly is Valgrind? From what I've gathered by listening to you talk about it, it's some kind of gdb replacement program... is it that much better? What does it do that gdb doesn't do? Where do I get my hands on it? Is it free/open source? :)

Actually, it's amazing how many bugs a stock MUD in C will generate when you put it through g++. I've heard many argue that being strict about pointer casts and all that isn't necessary; well, perhaps, but so many bugs slip through due to poor error checking and strict compilation. I've ported my code base to C++ and it's sooo much nicer to work in. Not to mention that I don't have to waste time making my own data structures; since the STL implements so many (e.g. list, vector), you can worry about more important things (e.g. game, improvement).

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #6 on Mon 10 Nov 2003 08:59 AM (UTC)
Message
Valgrind is a memory debugger. Not intended to replace GDB, but instead meant to work with it. You can find it here: http://developer.kde.org/~sewardj/

Yes, it's free, open source, etc. I have it installed on both my servers and allow all my clients to make use of it as needed.

One thing to keep in mind is that it eats up alot of CPU and RAM, so if you're in a shared environment you'll need to keep that in mind. But it's a fabulous tool for tracking down memory related problems.
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.


20,393 views.

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

Go to topic:           Search the forum


[Go to top] top

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