Click here to Skip to main content
13,147,376 members (25,629 online)
Rate this:
Please Sign up or sign in to vote.
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,,, and 2 executable binary files each using one another shared library( say which deals with files.

The purpose of 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.,, and have almost same behavior. They all have a class and declare and object of an handler which gets the instance of the singleton in 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.

Posted 7-Nov-12 23:52pm

1 solution

Rate this: bad
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:[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2017
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