Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#125 Allocating and deleting data across dll boundaries

1.10.2
closed-invalid
nobody
5
2004-09-01
2004-07-15
Henry
No

In windows you cannot allocate and delete data across
dll boundaries. Doing so will likely cause a crash.
This is relevant when using cppunit_dll.

CPPUNIT_NS_BEGIN::TestSuite have CPPUNIT_NS_BEGIN::Test
objects added via the CPPUNIT_TEST macro. This macro
allocated memory in the code to be tested, and is thus
in a different dll/exe to the cppunit code. When
cppunit deletes this memory in
CPPUNIT_NS_BEGIN::TestSuite::deleteContents(), it
causes memory corruption (it caused the program to
crash on my computer (Windows 2000) in release builds).

Similarly in CPPUNIT_NS_BEGIN::TextTestRunner (and
presumably other runners) outputters allocated in
different modules are deleted in the cppunit dll,
causing a crash.

Simple fix is to not delete the CPPUNIT_NS_BEGIN::Test
and CPPUNIT_NS_BEGIN::Outputter items, resulting in a
memory leak.

As a general rule of thumb, always design code such
that data is deleted by the same object / location that
allocated it.

Discussion

  • Logged In: YES
    user_id=196852

    This does works. You just have to take care to use the same
    version of the CRT across DLL and use the DLL version of the
    CRT.

    It would be quite impossible to pass std::string across DLL
    otherwise.

    Baptiste.

     
    • status: open --> closed-invalid