Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Thanks
Posted

1 solution

It may be that your linker is configured the wrong way. Try adding -rdynamic to the linker command line.

Refer to this answer which explains this behaviour:
http://stackoverflow.com/questions/8623657/multiple-instances-of-singleton-across-shared-libraries-on-linux[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900