Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux Singleton
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 8-Nov-12 0:52am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 273
1 Maciej Los 255
2 Aajmot Sk 234
3 Richard MacCutchan 200
4 Marcin Kozub 195
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100