[Insight-developers] ExceptionObject assignment crash on MSVC

Niels Dekker niels-xtk at xs4all.nl
Fri May 30 13:45:17 EDT 2008


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