Plug a few memory leaks.
authorcantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Fri, 19 Sep 2008 16:29:14 +0000 (16:29 +0000)
committercantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Fri, 19 Sep 2008 16:29:14 +0000 (16:29 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/branches/REL_1@521 de75baf8-a10c-0410-a50a-987c0e22f00f

xmltooling/impl/MemoryStorageService.cpp

index b297d65..fdef458 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
  *  Copyright 2001-2007 Internet2\r
- * \r
+ *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
@@ -16,7 +16,7 @@
 \r
 /**\r
  * MemoryStorageService.cpp\r
- * \r
+ *\r
  * In-memory "persistent" storage, suitable for simple applications.\r
  */\r
 \r
@@ -40,12 +40,12 @@ namespace xmltooling {
     public:\r
         MemoryStorageService(const DOMElement* e);\r
         virtual ~MemoryStorageService();\r
-        \r
+\r
         bool createString(const char* context, const char* key, const char* value, time_t expiration);\r
         int readString(const char* context, const char* key, string* pvalue=NULL, time_t* pexpiration=NULL, int version=0);\r
         int updateString(const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0);\r
         bool deleteString(const char* context, const char* key);\r
-        \r
+\r
         bool createText(const char* context, const char* key, const char* value, time_t expiration) {\r
             return createString(context, key, value, expiration);\r
         }\r
@@ -58,7 +58,7 @@ namespace xmltooling {
         bool deleteText(const char* context, const char* key) {\r
             return deleteString(context, key);\r
         }\r
-        \r
+\r
         void reap(const char* context);\r
         void updateContext(const char* context, time_t expiration);\r
         void deleteContext(const char* context) {\r
@@ -69,7 +69,7 @@ namespace xmltooling {
 \r
     private:\r
         void cleanup();\r
-    \r
+\r
         struct XMLTOOL_DLLLOCAL Record {\r
             Record() : expiration(0), version(1) {}\r
             Record(const string& s, time_t t) : data(s), expiration(t), version(1) {}\r
@@ -77,7 +77,7 @@ namespace xmltooling {
             time_t expiration;\r
             int version;\r
         };\r
-        \r
+\r
         struct XMLTOOL_DLLLOCAL Context {\r
             Context() {}\r
             Context(const Context& src) {\r
@@ -143,6 +143,7 @@ MemoryStorageService::~MemoryStorageService()
     shutdown_wait->signal();\r
     cleanup_thread->join(NULL);\r
 \r
+    delete cleanup_thread;\r
     delete shutdown_wait;\r
     delete m_lock;\r
 }\r
@@ -152,7 +153,7 @@ void* MemoryStorageService::cleanup_fn(void* cache_p)
     MemoryStorageService* cache = reinterpret_cast<MemoryStorageService*>(cache_p);\r
 \r
 #ifndef WIN32\r
-    // First, let's block all signals \r
+    // First, let's block all signals\r
     Thread::mask_all_signals();\r
 #endif\r
 \r
@@ -176,14 +177,14 @@ void MemoryStorageService::cleanup()
         shutdown_wait->timedwait(mutex.get(), m_cleanupInterval);\r
         if (shutdown)\r
             break;\r
-        \r
+\r
         unsigned long count=0;\r
         time_t now = time(NULL);\r
         m_lock->wrlock();\r
         SharedLock locker(m_lock, false);\r
         for (map<string,Context>::iterator i=m_contextMap.begin(); i!=m_contextMap.end(); ++i)\r
             count += i->second.reap(now);\r
-        \r
+\r
         if (count)\r
             m_log.info("purged %d expired record(s) from storage", count);\r
     }\r
@@ -234,9 +235,9 @@ bool MemoryStorageService::createString(const char* context, const char* key, co
         // It's dead, so we can just remove it now and create the new record.\r
         ctx.m_dataMap.erase(i);\r
     }\r
-    \r
+\r
     ctx.m_dataMap[key]=Record(value,expiration);\r
-    \r
+\r
     m_log.debug("inserted record (%s) in context (%s)", key, context);\r
     return true;\r
 }\r
@@ -270,7 +271,7 @@ int MemoryStorageService::updateString(const char* context, const char* key, con
         return 0;\r
     else if (time(NULL) >= i->second.expiration)\r
         return 0;\r
-    \r
+\r
     if (version > 0 && version != i->second.version)\r
         return -1;  // caller's out of sync\r
 \r
@@ -278,7 +279,7 @@ int MemoryStorageService::updateString(const char* context, const char* key, con
         i->second.data = value;\r
         ++(i->second.version);\r
     }\r
-        \r
+\r
     if (expiration && expiration != i->second.expiration)\r
         i->second.expiration = expiration;\r
 \r
@@ -290,7 +291,7 @@ bool MemoryStorageService::deleteString(const char* context, const char* key)
 {\r
     Context& ctx = writeContext(context);\r
     SharedLock locker(m_lock, false);\r
-    \r
+\r
     // Find the record.\r
     map<string,Record>::iterator i=ctx.m_dataMap.find(key);\r
     if (i!=ctx.m_dataMap.end()) {\r