Run time error: Debug assertion failure

  • Anonymous - 2001-06-19

       I am running Cppunit on Microsoft visual c++ 6.0+ service pack 4.2. I have loaded the cppunit source code and wrapped it up in a tsUnitTest namespace and built it as a .dll. On top of that, I built a simple window application running with an ad hoc test class. The compilation went fine. On execution however, it gave me "Debug assertion failure" dialogue. The problem seems to occur when the program is exitting out and cleaning up standard strings when destructing the TestSuite and TestResult. Running in debuggin mode, the call stack looks like:

    _free_dbg_lk(void * 0x00312668, int 1) line 1044 + 35 bytes
    _free_dbg(void * 0x00312668, int 1) line 1001 + 13 bytes
    free(void * 0x00312668) line 956 + 11 bytes
    operator delete(void * 0x00312668) line 7 + 10 bytes
    std::allocator<char>::deallocate(void * 0x00312668, unsigned int 33) line 64 + 16 bytes
    std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy(unsigned char 1) line 592
    std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() line 59 + 17 bytes
    tsUnitTest::TestCase::~TestCase() line 149 + 80 bytes
    tsUnitTest::TestCaller<ReportTest>::~TestCaller<ReportTest>() + 86 bytes
    tsUnitTest::TestCaller<ReportTest>::`scalar deleting destructor'(unsigned int 1) + 37 bytes
    tsUnitTest::TestSuite::deleteContents() line 13 + 34 bytes
    tsUnitTest::TestSuite::~TestSuite() line 73 + 74 bytes
    tsUnitTest::TestSuite::`scalar deleting destructor'(unsigned int 1) + 40 bytes
    main(int 1, char * * 0x003111a0) line 17 + 32 bytes
    mainCRTStartup() line 206 + 25 bytes
    KERNEL32! 77e992a6()

    Funny thing is, if I modify in compiling setting for the project to use MFC as a shared DLL, the run time error is gone. Nonetheless, my simple application use nothing from MFC.

    Anybody has any ideas? Thanks in advance.


    • Baptiste Lepilleur

      Weird, I believe I already answered that one.

      DLL and static library used different memory model. You can't delete memory that was allocated in a dll that was using a different memory model. The easy solution is to have a version of the library for each memory model (multithread, and multithread DLL).

      I think I'll make a FAQ out of that one ;-)

      Why are you using tsUnitTest instead of the CppUnit namespace ?


    • Anonymous - 2002-12-06

      I had also the same problem.
      As I understand, this is because of the use of std::string in the API functions and the exported
      API classes.

      The problem is that allocation of strings are
      done outside the API, but deallocation are done inside. ("outside" and "inside" might then be compiled for different memory models)

      Is it possible to change all "std::string"
      types in the API to "char *" ?
      This would probably fix the problem, and
      it would be a step (?) to make the at least the
      API independent of STL for better platformindependent support.
      (Or do all platforms support STL? :-)

      And if you fix this you don't have to make that FAQ :-)

      Sorry if this is a post on a dead thread,
      but I hope this was useful information and that
      my suggestion will be considered.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks