I am working on a project with class "A", which contains the static container class stl. This class is included both in my main program and in the .so file. The class uses a standard (implicit, not declared) constructor / destructor. The main program loads the .so file with dlopen () and, in its destructor, calls dlclose (). The program crashes after the main exits when glibc calls the destructor for the static member variable of the class. The problem is that when dlclose () is called, the destructor for the static variable is called, then when main exit () glibc also calls the destructor, which leads to double free.
I have 2 questions, namely:
1) In this particular case, why aren't there two copies of the static variable (yes, I know, that sounds a bit ridiculous, but since both the main program and the .so file have separately compiled βAβ, shouldn't they be each one?)
2) Is there a way to solve this problem without re-writing class "A" so as not to contain static member variables?
source share