Remove memory leak 20/69620/2
authorSomin Kim <somin926.kim@samsung.com>
Mon, 16 May 2016 06:51:22 +0000 (15:51 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Mon, 16 May 2016 09:08:36 +0000 (18:08 +0900)
- Release enabled rule instances

Change-Id: I0316530fe72395623fd287d6529ef6fb7aa9a01e
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
src/access_control/PeerCreds.cpp
src/trigger/ContextMonitor.cpp
src/trigger/ContextMonitor.h
src/trigger/RuleManager.cpp
src/trigger/Trigger.cpp

index 4fee21e..35fd152 100644 (file)
@@ -66,6 +66,7 @@ bool ctx::peer_creds::get(GDBusConnection *connection, const char *uniqueName, c
        *creds = new(std::nothrow) Credentials(packageId, client, session, user);
        IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed");
 
+       g_free(app_id);
        return true;
 
 CATCH:
index 56f5eed..5dab7f5 100644 (file)
@@ -50,9 +50,9 @@ ContextMonitor::~ContextMonitor()
 {
 }
 
-void ContextMonitor::setContextManager(ContextManager* ctx_mgr)
+void ContextMonitor::setContextManager(ContextManager* ctxMgr)
 {
-       __contextMgr = ctx_mgr;
+       __contextMgr = ctxMgr;
 }
 
 ContextMonitor* ContextMonitor::getInstance()
@@ -190,7 +190,7 @@ bool ContextMonitor::isAllowed(const char *client, const char *subject)
 int ContextMonitor::__findSub(RequestType type, const char* subject, Json* option)
 {
        // @return      request id
-       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &___readMap;
+       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &__readMap;
 
        Json jOpt;
        if (option) {
@@ -208,7 +208,7 @@ int ContextMonitor::__findSub(RequestType type, const char* subject, Json* optio
 
 bool ContextMonitor::__addSub(RequestType type, int sid, const char* subject, Json* option, IContextListener* listener)
 {
-       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &___readMap;
+       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &__readMap;
 
        SubscrInfo *info = new(std::nothrow) SubscrInfo(sid, subject, option);
        IF_FAIL_RETURN_TAG(info, false, _E, "Memory allocation failed");
@@ -220,7 +220,7 @@ bool ContextMonitor::__addSub(RequestType type, int sid, const char* subject, Js
 
 void ContextMonitor::__removeSub(RequestType type, const char* subject, Json* option)
 {
-       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &___readMap;
+       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &__readMap;
 
        Json jOpt;
        if (option) {
@@ -238,7 +238,7 @@ void ContextMonitor::__removeSub(RequestType type, const char* subject, Json* op
 
 void ContextMonitor::__removeSub(RequestType type, int sid)
 {
-       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &___readMap;
+       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &__readMap;
 
        SubscrInfo* info = map->at(sid);
        info->listenerList.clear();
@@ -252,7 +252,7 @@ void ContextMonitor::__removeSub(RequestType type, int sid)
 int ContextMonitor::__addListener(RequestType type, int sid, IContextListener* listener)
 {
        // @return      number of listeners for the corresponding sid
-       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &___readMap;
+       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &__readMap;
 
        auto it = map->find(sid);
 
@@ -265,7 +265,7 @@ int ContextMonitor::__addListener(RequestType type, int sid, IContextListener* l
 int ContextMonitor::__removeListener(RequestType type, int sid, IContextListener* listener)
 {
        // @return      number of listeners for the corresponding sid
-       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &___readMap;
+       std::map<int, SubscrInfo*>* map = (type == REQ_SUBSCRIBE)? &__subscrMap : &__readMap;
 
        auto it = map->find(sid);
 
@@ -293,8 +293,8 @@ void ContextMonitor::replyResult(int reqId, int error, const char* subject, Json
 {
        _D(YELLOW("Condition received: subject(%s), option(%s), fact(%s)"), subject, option->str().c_str(), fact->str().c_str());
 
-       auto it = ___readMap.find(reqId);
-       IF_FAIL_VOID_TAG(it != ___readMap.end(), _E, "Request id not found");
+       auto it = __readMap.find(reqId);
+       IF_FAIL_VOID_TAG(it != __readMap.end(), _E, "Request id not found");
 
        SubscrInfo* info = it->second;
        for (auto it2 = info->listenerList.begin(); it2 != info->listenerList.end(); ++it2) {
index d3c6966..473cac2 100644 (file)
@@ -34,7 +34,7 @@ namespace trigger {
        class ContextMonitor {
        public:
                static ContextMonitor* getInstance();
-               static void setContextManager(ContextManager* ctx_mgr);
+               static void setContextManager(ContextManager* ctxMgr);
                static void destroy();
 
                int subscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
@@ -75,7 +75,7 @@ namespace trigger {
                };
 
                std::map<int, SubscrInfo*> __subscrMap;
-               std::map<int, SubscrInfo*> ___readMap;
+               std::map<int, SubscrInfo*> __readMap;
 
                int __findSub(RequestType type, const char *subject, Json *option);
                bool __addSub(RequestType type, int sid, const char *subject, Json *option, IContextListener* listener);
index 75a5a1d..afb8107 100644 (file)
@@ -53,6 +53,19 @@ RuleManager::RuleManager()
 
 RuleManager::~RuleManager()
 {
+       // Release rule instances
+       _D("Release rule instances");
+       for (auto it = __ruleMap.begin(); it != __ruleMap.end(); ++it) {
+               Rule* rule = static_cast<Rule*>(it->second);
+
+               int error = rule->stop();
+               if (error != ERR_NONE) {
+                       _E("Failed to stop rule%d", it->first);
+               }
+
+               delete rule;
+       }
+       __ruleMap.clear();
 }
 
 bool RuleManager::init()
index ac56d3c..244ac1f 100644 (file)
@@ -97,6 +97,8 @@ void Trigger::__processRequest(RequestInfo* request)
        } else {
                _E("Invalid request");
        }
+
+       delete request;
 }
 
 void Trigger::__processInitialize(ContextManager* mgr)