User Name:


Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Yandex, DotBot

Members: 0
Guests: 14
Newest Member
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » AFKMud Support & Development » Memory Freeing Assiatance :(
Forum Rules | Mark all | Recent Posts

Memory Freeing Assiatance :(
< Newer Topic :: Older Topic > heh, me again, ain't i annoying? lo

Pages:<< prev 1 next >>
Post is unread #1 Feb 27, 2004, 10:41 am
Go to the top of the page
Go to the bottom of the page


JoinedDec 4, 2003

Heh, I'm still unsure on how to free memory without causing freeing null pointer, which i have seen a lot of when i try too...

and then when i put it at the end of the function thats making a memory leak.. The mud crashes when that function is used.. I'm having trouble getting this down correctly, could someone possible explain how its done correctly without losing any files, or crashing the game?

Peace, Thanks for your time...
Post is unread #2 Feb 27, 2004, 11:17 am
Go to the top of the page
Go to the bottom of the page

JoinedMar 5, 2005

Basically, make really, REALLY sure that if your assigning a sting with STRALLOC/fread_string, you always use STRALLoc to assign, and STRFREE to free it. If you use str_dup/fread_string_nohash, always use str_dup and DISPOSE.

If you allocate a local string inside of a function, you HAVE to free it. If you are going to be assigning into a global variable(ch->name, for example), check that it is allocated. If so, free it, then assign the new value.

If you are assigning with the wrong functions or not freeing properly, this can cause memory leaks.

Since I don't know specifics, thats about as much as I can help with. If you have example, I can show you how to do it properly.
Post is unread #3 Feb 27, 2004, 1:59 pm
Go to the top of the page
Go to the bottom of the page

JoinedMar 8, 2005

Never return a dynamically allocated object unless you know for sure that something else will free it later.

That one will save you MANY hours of frustration trying to hunt down small memory leaks. If you need to keep it around, make sure you don't lose track of it.. sometimes you can use static arrays for this, but only if it's not instance data (IE: two players getting a buffer for their description can't share the same static buffer, but two temporary results might be just fine with that).

Remember the phrase "Free the mallocs!"

Another good debugging tip is to always NULL your pointers after freeing them. It's easier to tell if something is free if it's 0, than if it still has the random memory address that isn't yours anymore.
Post is unread #4 Feb 27, 2004, 5:05 pm
Go to the top of the page
Go to the bottom of the page

Black Hand
JoinedJan 1, 2002

This would be why the STRFREE and DISPOSE macros in AFK both NULL the pointer once free'd. Did so as a convenience since many people tend to forget about doing that, myself included. NULLing it again won't hurt anything either.
Pages:<< prev 1 next >>