Fix memory leaks: ServiceRunner::~ServiceRunner deletes its service instance 49/142649/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 7 Aug 2017 02:34:09 +0000 (11:34 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 7 Aug 2017 02:34:09 +0000 (11:34 +0900)
Change-Id: Icff41cd89140d58fd60ad6ea92fb939dcc2bf047
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/server/ServiceRunner.cpp
src/server/ServiceRunner.h

index eb0b058..1bcddb6 100644 (file)
@@ -25,8 +25,8 @@
 using namespace ctx;
 
 ServiceRunner::ServiceRunner(GDBusConnection* conn, IService* service) :
-       serviceInstance(service),
-       started(false),
+       __serviceInstance(service),
+       __started(false),
        __uid(0),
        __connection(conn),
        __objPath(CTX_DBUS_PATH "/"),
@@ -34,12 +34,13 @@ ServiceRunner::ServiceRunner(GDBusConnection* conn, IService* service) :
        __nodeInfo(NULL),
        __registrationId(0)
 {
-       __objPath += serviceInstance->getServiceName();
-       __interface += serviceInstance->getServiceName();
+       __objPath += __serviceInstance->getServiceName();
+       __interface += __serviceInstance->getServiceName();
 }
 
 ServiceRunner::~ServiceRunner()
 {
+       delete __serviceInstance;
 }
 
 GMainContext* ServiceRunner::getMainContext()
@@ -54,14 +55,14 @@ GDBusConnection* ServiceRunner::getConnection()
 
 IService* ServiceRunner::getService()
 {
-       return serviceInstance;
+       return __serviceInstance;
 }
 
 bool ServiceRunner::start(uid_t uid)
 {
-       IF_FAIL_RETURN(!started, true);
+       IF_FAIL_RETURN(!__started, true);
 
-       _I(CYAN("Starting '%s'"), serviceInstance->getServiceName());
+       _I(CYAN("Starting '%s'"), __serviceInstance->getServiceName());
 
        if (!__init(uid)) {
                _E("Starting failed");
@@ -69,17 +70,17 @@ bool ServiceRunner::start(uid_t uid)
                return false;
        }
 
-       started = true;
+       __started = true;
        __uid = uid;
        return true;
 }
 
 void ServiceRunner::stop()
 {
-       IF_FAIL_VOID(started);
-       started = false;
+       IF_FAIL_VOID(__started);
+       __started = false;
 
-       _I(PURPLE("Stopping '%s'"), serviceInstance->getServiceName());
+       _I(PURPLE("Stopping '%s'"), __serviceInstance->getServiceName());
 
        __release(__uid);
 }
@@ -103,7 +104,7 @@ bool ServiceRunner::__init(uid_t uid)
        vtable.set_property = NULL;
 
        std::string introspection("<node><interface name='");
-       introspection += __interface + "'>" + serviceInstance->getMethodSpecs() + "</interface></node>";
+       introspection += __interface + "'>" + __serviceInstance->getMethodSpecs() + "</interface></node>";
 
        __nodeInfo = g_dbus_node_info_new_for_xml(introspection.c_str(), NULL);
        IF_FAIL_RETURN_TAG(__nodeInfo, false, _E, "NodeInfo creation failed");
@@ -161,9 +162,9 @@ ServiceClient* ServiceRunner::__getClient(const std::string& busName)
        ServiceClient* client = __createClient(busName);
        IF_FAIL_RETURN(client, NULL);
 
-       IMethodCallHandler* callHandler = serviceInstance->createMethodCallHandler(client);
+       IMethodCallHandler* callHandler = __serviceInstance->createMethodCallHandler(client);
        if (!callHandler) {
-               _E("%s's method call handler cannot be NULL.", serviceInstance->getServiceName());
+               _E("%s's method call handler cannot be NULL.", __serviceInstance->getServiceName());
                delete client;
                return NULL;
        }
@@ -186,7 +187,7 @@ void ServiceRunner::__onNameOwnerChanged(GDBusConnection* conn, const gchar* sen
 
 void ServiceRunner::__removeClient(const std::string& busName)
 {
-       _I("'%s' lost '%s'", serviceInstance->getServiceName(), busName.c_str());
+       _I("'%s' lost '%s'", __serviceInstance->getServiceName(), busName.c_str());
 
        auto iter = __clients.find(busName);
        IF_FAIL_VOID(iter != __clients.end());
@@ -219,24 +220,24 @@ SystemServiceRunner::SystemServiceRunner(GDBusConnection* conn, IService* servic
 
 void SystemServiceRunner::notifyUserNew(uid_t uid)
 {
-       if (started)
-               static_cast<ISystemService*>(serviceInstance)->onUserActivated(uid);
+       if (__started)
+               static_cast<ISystemService*>(__serviceInstance)->onUserActivated(uid);
 }
 
 void SystemServiceRunner::notifyUserRemoved(uid_t uid)
 {
-       if (started)
-               static_cast<ISystemService*>(serviceInstance)->onUserDeactivated(uid);
+       if (__started)
+               static_cast<ISystemService*>(__serviceInstance)->onUserDeactivated(uid);
 }
 
 bool SystemServiceRunner::__prepare(uid_t uid)
 {
-       return static_cast<ISystemService*>(serviceInstance)->prepare();
+       return static_cast<ISystemService*>(__serviceInstance)->prepare();
 }
 
 void SystemServiceRunner::__cleanup(uid_t uid)
 {
-       static_cast<ISystemService*>(serviceInstance)->cleanup();
+       static_cast<ISystemService*>(__serviceInstance)->cleanup();
 }
 
 ServiceClient* SystemServiceRunner::__createClient(const std::string& busName)
@@ -266,12 +267,12 @@ void UserServiceRunner::notifyUserRemoved(uid_t uid)
 
 bool UserServiceRunner::__prepare(uid_t uid)
 {
-       return static_cast<IUserService*>(serviceInstance)->prepare(uid);
+       return static_cast<IUserService*>(__serviceInstance)->prepare(uid);
 }
 
 void UserServiceRunner::__cleanup(uid_t uid)
 {
-       static_cast<IUserService*>(serviceInstance)->cleanup(uid);
+       static_cast<IUserService*>(__serviceInstance)->cleanup(uid);
 }
 
 ServiceClient* UserServiceRunner::__createClient(const std::string& busName)
@@ -284,7 +285,7 @@ ServiceClient* UserServiceRunner::__createClient(const std::string& busName)
        }
 
        if (!util::is_normal_user(client->getUid())) {
-               _W("%s does not support container users.", serviceInstance->getServiceName());
+               _W("%s does not support container users.", __serviceInstance->getServiceName());
                delete client;
                return NULL;
        }
index 0e7cf3d..d291f59 100644 (file)
@@ -46,8 +46,8 @@ namespace ctx {
        protected:
                ServiceRunner(GDBusConnection* conn, IService* service);
 
-               IService* serviceInstance;
-               bool started;
+               IService* __serviceInstance;
+               bool __started;
 
        private:
                static void __onMethodCalled(GDBusConnection* conn, const gchar* sender,