Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / September 2005



Tip: Looking for answers? Try searching our database.

Malloc Debug Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bruno - 08 Sep 2005 02:48 GMT
Hi ,

Has anyone ever managed to use "MallocDebug" with a command line application
generated with CW9.3 ?
I am failing lamentably and getting a bit annoyed ...
Here is what i did : In CW, I created a sample C 'HelloWorld' program using
the 'C Console Mach-O' template and stripped out all the MSL references out
of it. I removed all the librairies in order to link only against the
'System' framework and crt1.o binary. Invariably , In 'MallocDebug' when I
click on "Launch", after a while, I get the following error message :
"Unable to read malloc information from (null)"...

Thanks
Greg - 08 Sep 2005 12:22 GMT
> Hi ,
>
[quoted text clipped - 9 lines]
>
> Thanks

The "hello, world" console app just prints one line of text and exits.
To track memory leaks in an app, the app has to be running (and
preferably doing something).

It should not be necessary to remove any libraries from the program
being tested: just launch it within MallocDebug. MallocDebug will
ensure that the debug malloc library is loaded into the program's
space. All memory allocations end up calling the System's malloc
routine eventually; so if a program is leaking memory, MallocDebug will
show where the leaking allocations were made.

Greg
Bruno - 08 Sep 2005 13:23 GMT
> The "hello, world" console app just prints one line of text and exits.
> To track memory leaks in an app, the app has to be running (and
> preferably doing something).
Understood ! that was a bit stupid of myself..., now I got it to do
something: create a memory leak and loop indefinitely. But still,
MallocDebug fails to detect the leak .... Any ideas why (see code below)

//
void leak(int size)
{
   char *buff = malloc(size);
}

int main(int argc, char *argv[])
{
   printf("Hello World, this is CodeWarrior!\n");

   leak(100000);
   
   // Do something ... Or at least pretend
   do
   {
       ;
   }while(1);
   return 0;
}
//

> It should not be necessary to remove any libraries from the program
> being tested: just launch it within MallocDebug.
True and false : if you link against 'MSL All Mach O.lib', you can't use
MallocDebug : you get an error because the _exit symbol if defined twice.
You need to use a combination of the 'MSL C++ - BSD -MachO.lib' and the 'BSD
Runtime.lib'.

>MallocDebug will
> ensure that the debug malloc library is loaded into the program's
> space. All memory allocations end up calling the System's malloc
> routine eventually; so if a program is leaking memory, MallocDebug will
> show where the leaking allocations were made.
I knew that , thanks.

> Greg

Bruno
Ben Artin - 08 Sep 2005 23:45 GMT
> True and false : if you link against 'MSL All Mach O.lib', you can't use
> MallocDebug : you get an error because the _exit symbol if defined twice.
> You need to use a combination of the 'MSL C++ - BSD -MachO.lib' and the 'BSD
> Runtime.lib'.

True. (libgmalloc loses similarly)

Ben

Signature

If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>

Eric Albert - 09 Sep 2005 04:06 GMT
> > True and false : if you link against 'MSL All Mach O.lib', you can't use
> > MallocDebug : you get an error because the _exit symbol if defined twice.
> > You need to use a combination of the 'MSL C++ - BSD -MachO.lib' and the 'BSD
> > Runtime.lib'.
>
> True. (libgmalloc loses similarly)

Is this still true on Tiger?

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

Ben Artin - 09 Sep 2005 04:49 GMT
> > > True and false : if you link against 'MSL All Mach O.lib', you can't use
> > > MallocDebug : you get an error because the _exit symbol if defined twice.
[quoted text clipped - 5 lines]
>
> Is this still true on Tiger?

Haven't checked, and I am moving to Xcode anyway so I doubt I'll take the time
to do so :-)

Ben

Signature

If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>

Eric Albert - 09 Sep 2005 18:23 GMT
> > > > True and false : if you link against 'MSL All Mach O.lib', you
> > > > can't use MallocDebug : you get an error because the _exit
[quoted text clipped - 7 lines]
> Haven't checked, and I am moving to Xcode anyway so I doubt I'll take
> the time to do so :-)

Which is pretty much the same reason why I haven't checked. :)  But
libgmalloc and Malloc Debug were changed to work better in cases like
this for Tiger, so I wouldn't be surprised if it's fixed.

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.