Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 Couple bugs
Today, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, DotBot, Yahoo!, Sogou, Yandex

Members: 0
Guests: 17
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
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

RapidRunner

GroupMembers
Posts72
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

Greven
Magician
GroupMembers
Posts204
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

Quixadhal
Conjurer
GroupMembers
Posts398
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

Samson
Black Hand
GroupAdministrators
Posts3,639
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 >>