c++ - Why does this double-free error happen? -
i have base of operations , derived class:
in a.h:
//includes class { protected: static std::string a; //other dummy code };
in a.cpp
std::string a::a = "bar"; //other dummy code
in b.h:
#include "a.h" //other includes class b : public { public: int c; //other dummy code };
main.cpp:
#include "a.h" #include "b.h" int main() { printf("foo"); homecoming 0; }
now compile a.cpp , b.cpp 2 separate shared libraries "a.so" , "b.so" , link them against main.cpp. when run programme - quits corrupted-double-linked list error. running valgrind see there invalid free error. why happen?
i understand each .so file must have own re-create of static global variables, happens when derived class in different shared library while base of operations class in different shared library , there static variables in base of operations class? how memory allocated/destructed static variables in base of operations class, across libraries derived classes present?
i understand each .so file must have own re-create of static global variables
you understand incorrectly, unless linked a.o both a.so , b.so each .so file not have it's own re-create of static a::a. a.o should linked a.so , b.so shoould linked a.so, not a.o
c++ destructor double-free
No comments:
Post a Comment