Only delete storage service when we built it.
authorScott Cantor <cantor.2@osu.edu>
Thu, 25 Jan 2007 00:17:24 +0000 (00:17 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 25 Jan 2007 00:17:24 +0000 (00:17 +0000)
xmltooling/util/ReplayCache.cpp
xmltooling/util/ReplayCache.h

index 6ed4ab2..6566f1e 100644 (file)
@@ -26,7 +26,7 @@
 using namespace xmltooling;
 using namespace std;
 
-ReplayCache::ReplayCache(StorageService* storage) : m_storage(storage)
+ReplayCache::ReplayCache(StorageService* storage) : m_owned(storage==NULL), m_storage(storage)
 {
     if (!m_storage)
         m_storage = XMLToolingConfig::getConfig().StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE, NULL);
@@ -34,7 +34,8 @@ ReplayCache::ReplayCache(StorageService* storage) : m_storage(storage)
 
 ReplayCache::~ReplayCache()
 {
-    delete m_storage;
+    if (m_owned)
+        delete m_storage;
 }
 
 bool ReplayCache::check(const char* context, const char* s, time_t expires)
index 1300d89..590b519 100644 (file)
@@ -37,6 +37,9 @@ namespace xmltooling {
         
         /**
          * Creates a replay cache on top of a particular StorageService.
+         *
+         * The lifetime of the StorageService <strong>MUST</strong> be longer than
+         * the lifetime of the ReplayCache.
          * 
          * @param storage       pointer to a StorageService, or NULL to keep cache in memory
          */
@@ -59,6 +62,7 @@ namespace xmltooling {
         }
         
     private:
+        bool m_owned;
         StorageService* m_storage;
     };
 };