I'm facing a problem in singleton object in c++. Here is the explanation:
Problem info: I have a 4 shared libraries (say libA.so, libB.so, libC.so, libD.so) and 2 executable binary files each using one another shared library( say libE.so) which deals with files.
The purpose of libE.so is to write data into a file and if the executable restarts or size of file exceeds a certain limit it is zipped and a new file is created with time stamp in name. It is using singleton object. It exports a handler class for getting and using singleton. Compressing only happens in the above said two cases. The user/loader executable can specify the starting name of file only no other control is provided by handler class.
libA.so, libB.so, libC.so and libD.so have almost same behavior. They all have a class and declare and object of an handler which gets the instance of the singleton in libE.so and uses it for further purpose.
All these libraries are linked to two executable binary files. If only one of the two executable runs then its fine, But if both executable runs one after other then the file of the first started executable gets compressed.
Debug info: The constructor and destructor of the singleton object is called twice.(for each executable)
The object of singleton is a static object and never deleted.
The executable is not able to exit/return gives:
* glibc detected * (exe1 or exe2): double free or corruption (!prev): some_addr *
Running with binaries valgrind gives that the above error is due to the destructor of the singleton object.