and enforce your programmers to use only the wrapper.
Philip McGraw wrote:
Martin T. wrote:
Alex Blekhman wrote:
"Martin T." wrote:
... So the question is, is there any possibility of detecting leaks of
memory allocated with HeapAlloc ??
Your code won't detect memory leaks from HeapAlloc because it checks
only those allocations taht were made via CRT. HeapAlloc belongs to
Platform SDK, so by calling it directly you circumvent CRT allocation
bookeeping.
However, There are tools to detect meory leaks that were allocated with
PSDK functions, too:
(...)
Cheers. Looks promising, only ... anyone knows of a solution where one
could enable a page heap as described in the articles from sourcecode?
That way one could just enable the stuff in the debug version and be
done with it ...
(...)
Martin,
Which type of memory errors you are really trying to find: leaks
or overwrites (or both)? Your original question was about leaks,
but Alex's reply about page heap answers the problem of finding
heap memory overwrites.
(...)
Philip - thanks for the great explanation!
At the moment I'm primarily interested in a simple way to detect leaks.
(If I can detect overwrites - the better.)
Just some background:
My actual problem is as follows: We use the libxml2 library in our
program. For performance reasons we have switched out the std malloc/free
for this library with a set of functions that provide the malloc/free
services via the Heap*() API and a second low fragmentation heap in
addition to the default process heap.
Libxml2 returns some strings (unsigned char*) that are to be freed by the
calling code. For this we have a small C++ auto-ptr like class that does
this correctly.
However - if a programmer accidentally assigns such a return value to a
CString, the CString will just copy the (unsinged char*) and the string
from the libxml will leak.
Libxml2 comes with it's own set of memory detecting machinery, but that
does not integrate too well with the VS IDE (read: output to stderr).
Maybe I could also add some basic leak detection to my wrapper functions
for the Heap*() API ...
cheers,
Martin