[wx-dev] No debugging "new" and memory leak in hash.cpp

Eamon eamon at oxford-digital.com
Tue Jun 3 07:22:34 PDT 2008


Hi.

This is a bug report on wxMSW version 2.8.7.

I had a memory leak so I decided to turn on the debugging
version of new. I set the options in setup.h as below and
pressed build.

#define wxUSE_DEBUG_CONTEXT 1
#define wxUSE_MEMORY_TRACING 1
#define wxUSE_GLOBAL_MEMORY_OPERATORS 1
#define wxUSE_DEBUG_NEW_ALWAYS 1
#define wxUSE_ON_FATAL_EXCEPTION 1
#define wxUSE_STACKWALKER 1
#define wxUSE_DEBUGREPORT 1

I then rebuilt my project and still had the old "new" function.

Checked through everything and after a lot of builds and
recompiles found the following code in platform.h

#if defined(_MSC_VER) && (_MSC_VER >= 1310)
#    undef wxUSE_IOSTREAMH
#    define wxUSE_IOSTREAMH 0
#elif defined(__DMC__) || defined(__WATCOMC__)
#    undef wxUSE_IOSTREAMH
#    define wxUSE_IOSTREAMH 1
#elif defined(__MINGW32__)
#    undef wxUSE_IOSTREAMH
#    define wxUSE_IOSTREAMH 0
#endif /* compilers with/without iostream.h */

and because of the code at the bottom of object.h.

#ifdef __WXDEBUG__
    #define WXDEBUG_NEW new(__TFILE__,__LINE__)

    #if wxUSE_DEBUG_NEW_ALWAYS
        #if wxUSE_GLOBAL_MEMORY_OPERATORS
            #define new WXDEBUG_NEW
        #elif defined(__VISUALC__)
            // Including this file redefines new and allows leak reports to
            // contain line numbers
            #include "wx/msw/msvcrt.h"
        #endif
    #endif // wxUSE_DEBUG_NEW_ALWAYS
#else // !__WXDEBUG__
    #define WXDEBUG_NEW new
#endif // __WXDEBUG__/!__WXDEBUG__

We don't get the redefinition of new.

On my version of visual C++ "Microsoft Visual Studio 2005
Version 8.0.50727.762  (SP.050727-7600)" I put comments
round 
/*
#    undef wxUSE_IOSTREAMH
#    define wxUSE_IOSTREAMH 0
*/
and it rebuilt just fine.

I was then getting the filename and line number of the bad
code. 

However I was also getting lots of leaks from wxWidgets itself.

15:17:43: wxWidgets over/underwrite memory error:
15:17:43: ..\..\src\common\hash.cpp(735): non-object data at 0x394208, size 6 
15:17:43: wxWidgets over/underwrite memory error:
15:17:43: ..\..\src\common\hash.cpp(735): non-object data at 0x394208, size 6 
...
15:17:43: wxWidgets over/underwrite memory error:
15:17:43: ..\..\src\common\hash.cpp(735): non-object data at 0xB875C8, size 13 
15:17:43: wxWidgets over/underwrite memory error:
15:17:43: ..\..\src\common\hash.cpp(735): non-object data at 0xB875C8, size 13 

Hope this makes sense to someone.

Eamon.



More information about the wx-dev mailing list