[Insight-developers] ExceptionObject assignment crash on MSVC
Luis Ibanez
luis.ibanez at kitware.com
Fri May 30 14:08:21 EDT 2008
Hi Niels,
Removing the lines from the test may not be the right way to
address the problem. That will just give us a deceptively
green Dashboard and a false sense of security.
The memory leak reported for std::exception shouldn't result
in a crash, isn't it? ... it should just ... leak memory.
It may also be that the lines:
ExceptionObject &
ExceptionObject::operator= ( const ExceptionObject &orig )
{
// Assign its superclass:
static_cast<Superclass &>(*this) = orig;
are entering in an infinite loop calling itself (recursion).
(e.g.the operator= may have been declared virtual in
std::exception. This will make the program crash
when the calling stack overflows.
I'll try running this in Debug mode...
Luis
--------------------
Niels Dekker wrote:
> Bill Lorensen wrote:
>
>> itkExceptionObjectTest is now failing on some platforms:
>> http://www.cdash.org/CDash/testSummary.php?project=2&name=itkExceptionObjectTest&date=20080530
>>
>
>
> The failure of camelot.kitware (Linux-g++-4.3 20080530-0100-Nightly)
> looks irrelevant, because that build failed on 1327 other tests as well.
> http://www.cdash.org/CDash/viewTest.php?buildid=87527
>
> OTOH, the failures on MSVC 6 and MSVC 7.1 builds look rather serious.
> Fortunately I'm able to reproduce the crash locally, on MSVC 7.1. In
> itkExceptionObjectTest (itkExceptionObjectTest.cxx):
>
> E = F = G;
> std::cout << F << std::endl; // CRASH!
>
> The assignment has somehow corrupted F. I implemented the assignment of
> ExceptionObject as follows:
>
> ExceptionObject &
> ExceptionObject::operator= ( const ExceptionObject &orig )
> {
> // Assign its superclass:
> static_cast<Superclass &>(*this) = orig;
>
> // Assigns its smart pointer:
> m_ExceptionData = orig.m_ExceptionData;
> return *this;
> }
>
> The first part calls the assignment operator of the superclass, i.e.
> std::exception. Which seemed to me like The Right Way To Do. But I
> didn't know that MSVC's std::exception-assignment has a bug: "Memory
> leak on std::exception assignment operator"
> https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=328570
>
>
> Luis, if you have time, please feel free to remove those two lines of
> code from itkExceptionObjectTest.cxx:
>
> // Assign its superclass:
> static_cast<Superclass &>(*this) = orig;
>
> It appears to solve the crash instantly :-) I'm not 100 percent sure
> about the cause of the crash, but it very much looks like it's caused by
> std::exception's assignment. Unfortunately I don't get it properly
> tested anymore today. Otherwise it has to wait until tomorrow...
>
>
> Kind regards,
>
> Niels
>
More information about the Insight-developers
mailing list