From da3789f2ce2dbaf2ad6f73c894c3f24c6c2631e6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 14 Mar 2011 13:35:16 +0000 Subject: [PATCH] Fixing regression and rewrote portions of the memory handling of registered server plugins --- DataStructures/HashTable.h | 3 ++- Server/RequestHandler.h | 20 ++++++++++++++------ routed.cpp | 4 ---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/DataStructures/HashTable.h b/DataStructures/HashTable.h index 068863c2a..d77abbea3 100644 --- a/DataStructures/HashTable.h +++ b/DataStructures/HashTable.h @@ -53,8 +53,9 @@ public: } void EraseAll() { if(table.size() > 0) - table.clear(); + table.clear(); } + private: MyHashTable table; }; diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 681d31d7e..34bd4b186 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -34,10 +34,15 @@ namespace http { class RequestHandler : private boost::noncopyable { public: - explicit RequestHandler() { } + explicit RequestHandler() : _pluginCount(0) { } ~RequestHandler() { - pluginMap.EraseAll(); + + for(unsigned i = 0; i < _pluginVector.size(); i++) { + BasePlugin * tempPointer = _pluginVector[i]; + delete tempPointer; + } + } void handle_request(const Request& req, Reply& rep){ @@ -59,7 +64,7 @@ public: // std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl; // std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl; rep.status = Reply::ok; - pluginMap.Find(command)->HandleRequest(parameters, rep ); + _pluginVector[pluginMap.Find(command)]->HandleRequest(parameters, rep ); } else { rep = Reply::stockReply(Reply::badRequest); } @@ -73,12 +78,15 @@ public: void RegisterPlugin(BasePlugin * plugin) { std::cout << "[handler] registering plugin " << plugin->GetDescriptor() << std::endl; - pluginMap.Add(plugin->GetDescriptor(), plugin); + pluginMap.Add(plugin->GetDescriptor(), _pluginCount); + _pluginVector.push_back(plugin); + _pluginCount++; } private: - boost::mutex pluginMutex; - HashTable pluginMap; + HashTable pluginMap; + std::vector _pluginVector; + unsigned _pluginCount; }; } // namespace http diff --git a/routed.cpp b/routed.cpp index 4264f70eb..b93f46d84 100644 --- a/routed.cpp +++ b/routed.cpp @@ -89,10 +89,6 @@ int main (int argc, char *argv[]) std::cout << std::endl << "[server] shutting down" << std::endl; s->Stop(); t.join(); - delete helloWorld; - delete locate; - delete route; - delete h; delete s; } catch (std::exception& e) { std::cerr << "[fatal error] exception: " << e.what() << std::endl;