4

I have an application that uses boost logging. During shutdown, it gets an access violation on a null pointer access. When I step through the code to the point of failure, it appears that the boost::log dll is being de-allocated and then boost::thread code tries to access the memory that was once occupied by the log dll.

I am not using any boost threads in my own code, and so assume the boost-thread dll is used by boost log.

To ensure all sinks are destroyed prior to shutdown, I am calling: core->flush() and core->remove_all_sinks()

I am using boost 1.60 and have also tried this with boost 1.63. Same result.

Is there a way to ensure the boost logging core is shut down fully before exit / unload the dlls?

JeffV
  • 52,985
  • 32
  • 103
  • 124
  • Do you have a minimum code sample where the problem occurs? – Henrique Jung Feb 22 '17 at 01:45
  • "Boost.Log does not support plugin unloading because it saves references to various static data and code internally." - Boost Log author. Solved problem by avoiding use of boost log in my plugin since it does not support my use case. – JeffV Feb 24 '17 at 13:25
  • Do you mean application shutdown or system shutdown? – KonstantinL Feb 28 '17 at 12:50
  • DLL Unload. The application a dll plugin in a game engine. When the plugin is unloaded, the boost log dll and boost thread dlls are also unloaded. It is this time when boost thread code is accessing code space (RAM) that was just previously occupied by boost log code. – JeffV Mar 01 '17 at 17:35
  • @JeffV, are you aware of the contraints that DllMain has? Just in case: http://stackoverflow.com/questions/17259729/loading-calling-ntdll-from-dllmain – KonstantinL Mar 07 '17 at 07:37

1 Answers1

1

This problem might be with locale object set by the boost system. Similarly in your case this locale might be getting destroyed before Boost.Log is deinitialized, which results in a crash.

As per boost docs particularly log file rotation module. They have provided a workaround for similar case Boost known issues

Solution would be to initialize locale in main loop so that boost will have enough cycles to make cleanup at the end.

int main(int argc, char* argv[])
{
    boost::filesystem::path::imbue(std::locale("C"));
    initialize_log();

    // ...
}
Mandar
  • 1,006
  • 11
  • 28