[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] malloc-debugger problems

From: Greg Chicares
Subject: [lmi] malloc-debugger problems
Date: Sun, 04 Dec 2005 19:13:55 +0000
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Synopsis: We need a malloc debugger because it saves a very great deal
of debugging effort, letting us spend more time on development. The only
reasonable choice for msw seems to be mpatrol, which worked with older
toolsets, but no longer works with the compiler or wx library we use in
production. Yet both those tools are out of date and need to be upgraded.


1. What's a malloc debugger?

2. Why use one?

3. Why choose mpatrol?

4. mpatrol was made to work with older toolsets

5. mpatrol doesn't work with newer toolsets

6. What's the best solution for newer toolsets?

In detail:

1. What's a malloc debugger?

| The mpatrol library is a powerful debugging tool that attempts to
| diagnose run-time errors that are caused by the wrong use of
| dynamically allocated memory.

2. Why use one?

| automatically detect many memory management [...] bugs, avoiding
| hours of frustrating bug-hunting, making your programs more stable

3. Why choose mpatrol?

It's the best choice for msw:


and it works on other platforms, too, even though valgrind is
probably best for GNU/Linux.

4. mpatrol was made to work with older toolsets

See this discussion:


and the extensive documentation in this archive's 'README':


in particular with respect to wxString's inline dtor.

Here's another explanation of the problem with inline dtors:


Here's a workaround:


that helps prevent the inline-dtor with wxString etc.

Here's a patch for another problem observed with wx:


and a unit test for it:


With yesterday's 20051204T0157Z cvs commits to the skeleton branch,
mpatrol once again works, with gcc-3.2.3 (MinGW 20030915 release)
and wx-2.5.1 only.

5. mpatrol doesn't work with newer toolsets

Non-GUI unit tests work fine with mpatrol, using gcc-3.4.2 . The
problem is GUI code.

Again using the skeleton branch as of 20051204T0157Z, as in the
preceding list item, problems occur with gcc-3.4.2 (MinGW 20050120)
and wx-2.5.4 (and, of course, with wx and mpatrol obligatorily
rebuilt with the same compiler).

Open 'skeleton.exe' and close it immediately: the msvc rtl reports

| Runtime Error!
| Program: C:\opt\skeleton\bin\skeleton.exe
| This application has requested the Runtime to terminate it in an unusual way.
| Please contact the application's support team for more information.

and 'mpatrol.log' says:

| total warnings:    0
| total errors:      3

The errors all seem to involve wxString: demangling the internal
names that mpatrol reports yields

  C:/MinGW-20050120/bin[0]$./c++filt _ZN8wxStringaSERKS_
  wxString::operator=(wxString const&)

  C:/MinGW-20050120/bin[0]$./c++filt _ZN8wxStringD1Ev

  C:/MinGW-20050120/bin[0]$./c++filt _ZN8wxStringC1Ev

Running the GUI unit tests (Test | Unit test) results in an
'mpatrol.log' that's over a megabyte, instead of 3K as for a clean
run; it reports 429 errors.

These problems are not prevented by the techniques described here:
  export GLIBCXX_FORCE_NEW=1; ./skeleton
  export GLIBCPP_FORCE_NEW=1; ./skeleton
or, alternatively,
  build with "CPPFLAGS='-D__USE_MALLOC'"

6. What's the best solution for newer toolsets?

  a. Go bare--just don't use a malloc debugger.

Not acceptable. I've spent multiple days tracking down a single
memory-allocation error in production that could have been found
immediately in development with mpatrol. We've already gone too
long (since 2005-01) without a malloc debugger, at too great a cost.

  b. Use a different malloc debugger.

I don't know of any free alternative to mpatrol that works under msw;
had suggested dmalloc, but
it seemed very unpromising for msw three years ago. And I hesitate to
trade one tool's known set of problems for another's unknowns.

  c. Try addressing the problem by changing wx.

I don't know whether this would work, but it's worth a try. It may
not be easy. And we don't really know whether wx is the cause of
the problem: it might be the compiler. To rule that out, I tried
building wx-2.5.1 with MinGW gcc-3.4.2, but got many occurrences
of this error:

  ../../include/wx/msw/private.h:342: error: `cbSize' undeclared (first use 
this function)

Perhaps writing all wx destructors out of line would solve the
problem, but that's just speculation; yet that probably ought to
be done anyway. A good place to start might be the wxString classes,
because they seem to be implicated in the mpatrol error messages
reported above. Apparently some work was done along these line years

| This has been fixed by Gilles

but cvs HEAD:


still shows five inline dtors.

  d. Find more workarounds like lmi's 'wx_new.?pp'.

I don't think this would be easy. IIRC, 'wx_new.?pp' prevented memory
leaks, not memory-allocation errors, and it certainly didn't prevent
segfaults--but now we have errors and a segfault--so it might be
altogether futile.

At any rate, other efforts to resolve wx issues in lmi code have
turned out to be bad ideas--for example, lmi's 'wx_workarounds.hpp',
turned out to conflict with a different solution to the same problem
that was applied to a later version of wx; or, for another example,
the 'Window'-menu problem
that mysteriously unmanifests itself when a previously-necessary lmi
workaround is reverted.

  e. Revert to gcc-3.2.3 and wx-2.5.1 .

Reverting the compiler is silly. Reverting wx is impracticable:
the new product editor will need the latest version; and it's
already too painful to be using even wx-2.5.4 . So this is the
worst solution except for every other one available today.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]