From 43d08f386117cbeeee1de1fe2ba8248554c1aef1 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 21 Sep 2020 14:03:14 +0200 Subject: cppunittester: Do not unload test libraries At least on Windows, e6dfaf9f44f9939abc338c83b3024108431d0f69 "Turn OUStringLiteral into a consteval'ed, static-refcound rtl_uString" caused CppunitTest_sc_tablesheetsobj to fail at exit, when the static OUString aCacheName in ScDocument::GetTable (sc/source/core/data/document.cxx) is destroyed but references constexpr OUStringLiteral gaSrcSheetName(u"SheetToCopy") from test/source/sheet/xspreadsheets2.cxx in Library_subsequenttest, referenced (only) by the CppunitTest_sc_tablesheetsobj library, and both those libraries had already been unloaded from memory. Change-Id: Icea85019611fbaec3603f37b234e9e6fe3502961 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103103 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sal/cppunittester/cppunittester.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sal') diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx index a760ecf8ff41..0a833de5fba2 100644 --- a/sal/cppunittester/cppunittester.cxx +++ b/sal/cppunittester/cppunittester.cxx @@ -254,9 +254,14 @@ public: // call the initialize methods of the CppUnitTestPlugIns that // we statically link to the app executable. #else - CppUnit::PlugInManager manager; + // The PlugInManager instance is deliberately leaked, so that the dynamic libraries it loads + // are never unloaded (which could make e.g. pointers from other libraries' static data + // structures to const data in those libraries, like some static OUString cache pointing at + // a const OUStringLiteral, become dangling by the time those static data structures are + // destroyed during exit): + auto manager = new CppUnit::PlugInManager; try { - manager.load(testlib, args); + manager->load(testlib, args); } catch (const CppUnit::DynamicLibraryManagerException &e) { std::cerr << "DynamicLibraryManagerException: \"" << e.what() << "\"\n"; #ifdef _WIN32 -- cgit