diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc index c4df42fa5..ca4a6f7ad 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc @@ -15,6 +15,7 @@ #include "inmemorystoragemt.hh" using maxscale::SpinLockGuard; +using std::auto_ptr; InMemoryStorageMT::InMemoryStorageMT(const std::string& name, uint32_t ttl) : InMemoryStorage(name, ttl) @@ -27,11 +28,11 @@ InMemoryStorageMT::~InMemoryStorageMT() } // static -InMemoryStorageMT* InMemoryStorageMT::create(const std::string& name, - uint32_t ttl, - int argc, char* argv[]) +auto_ptr InMemoryStorageMT::create(const std::string& name, + uint32_t ttl, + int argc, char* argv[]) { - return new InMemoryStorageMT(name, ttl); + return auto_ptr(new InMemoryStorageMT(name, ttl)); } cache_result_t InMemoryStorageMT::get_info(uint32_t what, json_t** ppInfo) const diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh index af68aa87e..48708d958 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh @@ -21,7 +21,9 @@ class InMemoryStorageMT : public InMemoryStorage public: ~InMemoryStorageMT(); - static InMemoryStorageMT* create(const std::string& name, uint32_t ttl, int argc, char* argv[]); + typedef std::auto_ptr SInMemoryStorageMT; + + static SInMemoryStorageMT create(const std::string& name, uint32_t ttl, int argc, char* argv[]); cache_result_t get_info(uint32_t what, json_t** ppInfo) const; cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppresult); diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc index 791e8ee64..61e6fed06 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc @@ -14,6 +14,8 @@ #define MXS_MODULE_NAME "storage_inmemory" #include "inmemorystoragest.hh" +using std::auto_ptr; + InMemoryStorageST::InMemoryStorageST(const std::string& name, uint32_t ttl) : InMemoryStorage(name, ttl) { @@ -24,11 +26,11 @@ InMemoryStorageST::~InMemoryStorageST() } // static -InMemoryStorageST* InMemoryStorageST::create(const std::string& name, - uint32_t ttl, - int argc, char* argv[]) +auto_ptr InMemoryStorageST::create(const std::string& name, + uint32_t ttl, + int argc, char* argv[]) { - return new InMemoryStorageST(name, ttl); + return auto_ptr(new InMemoryStorageST(name, ttl)); } cache_result_t InMemoryStorageST::get_info(uint32_t what, json_t** ppinfo) const diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh index 62e84f49e..b86cdf521 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh @@ -20,7 +20,9 @@ class InMemoryStorageST : public InMemoryStorage public: ~InMemoryStorageST(); - static InMemoryStorageST* create(const std::string& name, uint32_t ttl, int argc, char* argv[]); + typedef std::auto_ptr SInMemoryStorageST; + + static SInMemoryStorageST create(const std::string& name, uint32_t ttl, int argc, char* argv[]); cache_result_t get_info(uint32_t what, json_t** ppinfo) const; cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppresult); diff --git a/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc b/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc index 755556f5c..5976e8e09 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc @@ -18,6 +18,8 @@ #include "inmemorystoragest.hh" #include "inmemorystoragemt.hh" +using std::auto_ptr; + namespace { @@ -50,33 +52,33 @@ CACHE_STORAGE* createInstance(cache_thread_model_t model, "does not enforce such a limit.", (unsigned long)max_size); } - InMemoryStorage* pStorage = NULL; + auto_ptr sStorage; switch (model) { case CACHE_THREAD_MODEL_ST: - MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv)); + MXS_EXCEPTION_GUARD(sStorage = InMemoryStorageST::create(zname, ttl, argc, argv)); break; default: ss_dassert(!true); MXS_ERROR("Unknown thread model %d, creating multi-thread aware storage.", (int)model); case CACHE_THREAD_MODEL_MT: - MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv)); + MXS_EXCEPTION_GUARD(sStorage = InMemoryStorageST::create(zname, ttl, argc, argv)); break; } - if (pStorage) + if (sStorage.get()) { MXS_NOTICE("Storage module created."); } - return reinterpret_cast(pStorage); + return reinterpret_cast(sStorage.release()); } void freeInstance(CACHE_STORAGE* pinstance) { - delete reinterpret_cast(pinstance); + MXS_EXCEPTION_GUARD(delete reinterpret_cast(pinstance)); } cache_result_t getInfo(CACHE_STORAGE* pStorage,