Skip to content

Commit

Permalink
* static initialization order change
Browse files Browse the repository at this point in the history
MutexFactory and SecureMemoryRegistry are now manually instantiated to ensure a graceful destruction when process stops
  • Loading branch information
agrandville committed Sep 19, 2015
1 parent 08ffa75 commit 3b087c7
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 14 deletions.
16 changes: 16 additions & 0 deletions src/lib/SoftHSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@

#include <stdlib.h>

// Initialise the one-and-only instance

#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif

#ifdef HAVE_CXX11
std::unique_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(nullptr);
#else
std::auto_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(NULL);
#endif



static CK_RV newP11Object(CK_OBJECT_CLASS objClass, CK_KEY_TYPE keyType, CK_CERTIFICATE_TYPE certType, P11Object **p11object)
{
switch(objClass) {
Expand Down
7 changes: 0 additions & 7 deletions src/lib/common/MutexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ MutexLocker::~MutexLocker()
MutexFactory implementation
*****************************************************************************/

// Initialise the one-and-only instance
#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif

// Constructor
MutexFactory::MutexFactory()
{
Expand Down
13 changes: 13 additions & 0 deletions src/lib/crypto/test/cryptotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
#include "CryptoFactory.h"
#include "SecureMemoryRegistry.h"

// Initialise the one-and-only instance
#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif

#ifdef HAVE_CXX11
std::unique_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(nullptr);
#else
std::auto_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(NULL);
#endif

int main(int /*argc*/, char** /*argv*/)
{
CppUnit::TextUi::TestRunner runner;
Expand Down
7 changes: 0 additions & 7 deletions src/lib/data_mgr/SecureMemoryRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
#include "log.h"
#include "SecureMemoryRegistry.h"

// Initialise the one-and-only instance
#ifdef HAVE_CXX11
std::unique_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(nullptr);
#else
std::auto_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(NULL);
#endif

// Constructor
SecureMemoryRegistry::SecureMemoryRegistry()
{
Expand Down
13 changes: 13 additions & 0 deletions src/lib/data_mgr/test/datamgrtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
#include "CryptoFactory.h"
#include "SecureMemoryRegistry.h"

// Initialise the one-and-only instance
#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif

#ifdef HAVE_CXX11
std::unique_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(nullptr);
#else
std::auto_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(NULL);
#endif

int main(int /*argc*/, char** /*argv*/)
{
CppUnit::TextUi::TestRunner runner;
Expand Down
7 changes: 7 additions & 0 deletions src/lib/handle_mgr/test/HandleManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
#include <cppunit/extensions/HelperMacros.h>
#include "HandleManagerTests.h"

#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif


CPPUNIT_TEST_SUITE_REGISTRATION(HandleManagerTests);

void HandleManagerTests::setUp()
Expand Down
2 changes: 2 additions & 0 deletions src/lib/handle_mgr/test/handlemgrtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>



int main(int /*argc*/, char** /*argv*/)
{
CppUnit::TextUi::TestRunner runner;
Expand Down
14 changes: 14 additions & 0 deletions src/lib/object_store/test/ObjectStoreTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
#include "OSAttributes.h"
#include "cryptoki.h"

// Initialise the one-and-only instance
#ifdef HAVE_CXX11
std::unique_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(nullptr);
#else
std::auto_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(NULL);
#endif

#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif


CPPUNIT_TEST_SUITE_REGISTRATION(ObjectStoreTests);

// FIXME: all pathnames in this file are *NIX/BSD specific
Expand Down
12 changes: 12 additions & 0 deletions src/lib/slot_mgr/test/SlotManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
#include "CryptoFactory.h"
#include "cryptoki.h"

#ifdef HAVE_CXX11
std::unique_ptr<MutexFactory> MutexFactory::instance(nullptr);
#else
std::auto_ptr<MutexFactory> MutexFactory::instance(NULL);
#endif

#ifdef HAVE_CXX11
std::unique_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(nullptr);
#else
std::auto_ptr<SecureMemoryRegistry> SecureMemoryRegistry::instance(NULL);
#endif

CPPUNIT_TEST_SUITE_REGISTRATION(SlotManagerTests);

void SlotManagerTests::setUp()
Expand Down

0 comments on commit 3b087c7

Please sign in to comment.