Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Third Degree reports memory leak within fopen?
@ 1999-01-04  5:00 core__dump
  1999-01-05  5:00 ` John P Williams
  0 siblings, 1 reply; 2+ messages in thread
From: core__dump @ 1999-01-04  5:00 UTC (permalink / raw)


When I run Thrid Degree on a simple program that contains a call
to "fopen" on a Digital UNIX V4.0B  (Rev. 564) machine, third degree
reports a memory leak.

Here is the test program:


#include <stdio.h>
main()
{
   FILE *fd;
   if( (fd = fopen("test.txt","w")) == NULL) {
     perror("Error with fopen:");
     exit(1);
   }
   fclose(fd);
}




Here is the contents of the Third Degree log file:


Third Degree version 4.2
testprog.third run by root on f22a, Wed Dec 30 11:25:49 1998

No .third or //.third file found.

------------------------------------------------------------------------
------------------------------------------------------------------------
Searching for new leaks in heap after program exit

48 bytes in 1 leak (including 1 super leak) created at:
    malloc                         libc.so
    _findiop                       libc.so
    fopen                          libc.so
    main                           testprog
    __start                        testprog

------------------------------------------------------------------------
------------------------------------------------------------------------
memory layout at program exit
	heap      		57344 	bytes [0x140002000-0x140010000]
	stack       		1328 	bytes [0x11ffffad0-0x120000000]
	testprog data       	8192 	bytes [0x140000000-0x140002000]
	/usr/shlib/libc.so data 105296	bytes [0x3ffc0800000-0x3ffc0819b50]
	testprog text     	393216 	bytes [0x120000000-0x120060000]
	/usr/shlib/libc.so text	2686976	bytes [0x3ff80800000-0x3ff80a90000]


Is there really a memory leak within "fopen"?

Thanks
DM

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Third Degree reports memory leak within fopen?
  1999-01-04  5:00 Third Degree reports memory leak within fopen? core__dump
@ 1999-01-05  5:00 ` John P Williams
  0 siblings, 0 replies; 2+ messages in thread
From: John P Williams @ 1999-01-05  5:00 UTC (permalink / raw)


> When I run Thrid Degree on a simple program that contains a call
> to "fopen" on a Digital UNIX V4.0B  (Rev. 564) machine, third degree
> reports a memory leak.

The fopen libc-call does allocate a small amount of memory which
it does not free. Third Degree cannot find a reference to that
memory after the program exits (perhaps erroneously, since its 
algorithm can not accurately diagnose optimized code), so it reports
it as a "leak" instead of as a live "object".

In this particular case, the heap block is allocated at start up
and remains in use until program exit, so while it is certainly
heap memory that was not freed, it is not a case that you should
worry about because it does not hurt performance - in fact it is
designed this way in order to improve performance. We have no plans to
change this code or other libc code that leaves memory allocated until 
the program exits, because the current code has better performance.

However, newer versions of Third Degree already suppress warnings
like this for system libraries, whose design and coding is often
sufficiently optimized as to cause reports like this one that 
should always be ignored.

Even when your own code triggers reports of leaks or other bad things,
you need to consider the seriousness of the issue for the main goals
of your application. Leaking a heap block every time around a loop
is usually a serious problem, because the amount of memory lost is
proportional to the iteration count. But losing just 48 bytes at the end
of the program is not usually going to be a problem. If your application
really can't afford to leave 48 bytes allocated for the duration of its
execution, then it should probably not use the stdio package. You can use
both the leak-size and the leak-count as indicators of seriousness. A
single large leak early in the program might be a problem, but otherwise a
single leak at or near the end of the program is unlikely to be a problem.
	
I hope Third Degree is proving useful in analyzing your application.
We recommend analyzing only code that is compiled for debugging (with
the -g, -g1 or -g2 flags) though instrumenting libc is often worthwhile
to show up problems in the debuggable application code that calls it.

	John P Williams, DIGITAL UNIX Development Environment Group, Compaq



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-01-05  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-01-04  5:00 Third Degree reports memory leak within fopen? core__dump
1999-01-05  5:00 ` John P Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox