logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malcolm Melville <malc...@ixa2a.com>
Subject Memory leak: Windows DLL build only
Date Wed, 24 Nov 2004 22:24:09 GMT
It appears to me that there is a memory leak from tchar.h under Windows 
in DLL mode. Each construct/destruct cycle of a StringBuffer causes a 4 
byte leak to be reported by Purify and Leak Browser.

The following code fragment - a stripped out version of tchar.h with 
just the offending code in it shows the problem. Compile with gcc/linux 
or gcc/Mac OS X and its fine. Compile with MSVC 7.1 in Multi threaded 
DLL mode and the process grows. Compile with MSVC 7.1 in Multi threaded 
or single threaded mode and its fine.

My reading of the STL (and Rogue Wave) docs says that its all fine to 
call init() with your own buffer, if that is the probelm which is what 
Purify suggests. But maybe someone else has spotted this and there is a 
work around for what seems to be an MS problem. I see that the code is 
pretty much the same in CVS so though I have only looked at 0.9.7, I 
guess its true of what is coming as well.

Any views/comments welcome. I am looking for a work around.


#include <iostream>
#include <cwchar>
#include <streambuf>
using namespace std;

#include <sys/resource.h>
#include <unistd.h>

class mstringbuf : public std::basic_streambuf<wchar_t> {
	typedef std::allocator<char_type> allocator_type;

		char_type * b = pbase();
		if (b)
			al.deallocate(b, epptr() - b);

	allocator_type al;

class StringBuffer : public std::basic_ostream<wchar_t> {
	StringBuffer() : std::basic_ostream<wchar_t>(0)
		{ this->init(&buffer); }

	mstringbuf buffer;

int main(int argc, char* argv[])
    int result=0;
    for (unsigned long i=0; i<100000000; i++) {
       StringBuffer sb;

Malcolm Melville                    email:   malcolm@ixa2a.com
ixa2a ltd.                                   malcolm@eml.co.uk
Software and technical services     Tel:     +44 1435 831159
                                     FAX:     +44 1435 830216
Enterprise Melville Limited         Mobile:  07771 781478
Network and Aviation Consultancy

View raw message