>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
On 01.03.00, 02:18:36, Sean <sean at binky.net> wrote regarding Re: [ILUG]
memory leaks...:
> kevin lyda wrote something:
> { i had a question here but i seem to have answered it, so i thought
i'd
> { share...
> He's back ;-) Wheres me t-shirt ?/??
> {
> { memory leaks are really annoying. and they're also tough to spot.
> { glibc provides a method to spot them:
> {
> { #include <mcheck.h>
> {
> { and then call mtrace() at the start of main(). compile the program
with
> { -g for debugging, and set the environment variable MALLOC_TRACE to a
> { file to log memory allocation and freeing. once you've run the
program
> { run this:
> {
> { mtrace <program> $MALLOC_TRACE
> {
> follow up:
> I've tried this before with the following prog:
> --BEGIN
> #include <mcheck.h>
> #include <stdio.h>
> #include <stdlib.h>
> int main(int argc, char *argv[])
> {
> int i;
> char *buff;
> mtrace(); /* for mtrace */
> for (i = 0; i < 10; i++) buff = malloc(i * i * sizeof(char));
> free(buff);
> return 0;
> }
> --END
> (stupid I know, but an example)
> mtrace does:
> Memory not freed:
> -----------------
> Address Size Caller
> 0x08049690 0x1 at /home/sean/c/mem.c:13
> 0x080496a0 0x2 at /home/sean/c/mem.c:13
> 0x080496b0 0x3 at /home/sean/c/mem.c:13
> 0x080496c0 0x4 at /home/sean/c/mem.c:13
> 0x080496d0 0x5 at /home/sean/c/mem.c:13
> 0x080496e0 0x6 at /home/sean/c/mem.c:13
> 0x080496f0 0x7 at /home/sean/c/mem.c:13
> 0x08049700 0x8 at /home/sean/c/mem.c:13
> 0x08049710 0x9 at /home/sean/c/mem.c:13
> Electric fence brings an error up:
> ElectricFence Aborting: Allocating 0 bytes, probably a bug.
> { voila, it lists all the memory leaks and the lines where the memory
was
> { allocated.
> Not bad. This together with other tools could lead to entensive
debugging...
> Still not totally an excuse for remembering the [m|c]allocs ones
does
> while programming, but a help. Its better than most.
The bees knees when it comes to this stuff though is purify from
rational rose, no version for linux unfortunately, but has one for
solaris. At it seriously kicks ass, I have to say I love it. Memory
leak tracing plus electric fence style bounds error flagging for
dynamic and static arrays. Uninitialized reads as well, reads from
past the end of a file etc etc. Great stuff altogether. One of the few
pieces of development software which I would recommend that you buy, a
killer app in favour of solaris :-)
C.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!