This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Compile Time Memory Leak Analyses


I was wondering if anyone has given the following idea any thought:

Provide a method of tagging functions (perhaps automatically) on the
memory behavior of there parameters and what they return.  That is tagging
each parameter which is a pointer as either unconditionally freeing a
pointer passed in, conditionally freeing a pointer, or never freeing a
pointer.  And tagging the pointer returned as always needing to be freed,
sometimes needing to be freed, or never needing to be freed.

This information can then be used to detect simple memory problems by
performing flow analyses on a pointer and determine if:
1) A pointer is never freed when should be
2) An already deleted pointer is freed
3) A pointer is freed that shouldn't be

Of course when functions are used that are in the "conditional" class, or
a pointer is copied around several times and it is not possible to
determine if it all of them go out of scope before the data pointed to by
them is freed.  However, it will get a good deal of the simpler cases and
can help a lot of people out by detecting the obvious memory problems.

A similar analyses can be used when a garbage collector is used to
automatically delete blocks of memory when it can be determined that all
pointers pointing to by that memory goes out of scope.  This has the
potential to greatly red using memory usage.

I am not saying that it will be easy (especially the part of the automatic
tagging) however I defiantly think it is possible and would greatly reduce
memory problems in some programs.

---
Kevin Atkinson
kevina at users sourceforge net
http://www.ibiblio.org/kevina/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]