fix memory leak
authorYoungjae Shin <yj99.shin@samsung.com>
Tue, 24 Mar 2020 03:14:25 +0000 (12:14 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 24 Mar 2020 03:18:38 +0000 (12:18 +0900)
plugin/TestPlugin.cpp

index 7f370f6c1f51ceff938912b0acafcf1802f90b6b..fd65120efb15cb3cccec4390d7edacdb775f0f3a 100644 (file)
@@ -41,8 +41,11 @@ public:
 private:
        static gboolean changeTimeout(gpointer data)
        {
+               RETV_IF(nullptr == data, G_SOURCE_REMOVE);
+
                TestPluginAction *testAction = (TestPluginAction*)data;
                testAction->callChangedCB();
+
                return  G_SOURCE_REMOVE;
        }
 };
@@ -88,10 +91,12 @@ int TestPlugin::set(const std::string &key, int val, PluginAction **piAction)
                DBG("set(%s, %d)", key.c_str(), val);
                return MODES_ERROR_SYSTEM;
        } else if ("changeTime" == key) {
-               g_timeout_add_seconds(val, changeTimeout, (void*)testAction);
+               if (piAction)
+                       g_timeout_add_seconds(val, changeTimeout, (void*)testAction);
                DBG("set(%s, %d)", key.c_str(), val);
        } else {
                ERR("Unknown key(%s)", key.c_str());
+               delete testAction;
                return MODES_ERROR_NOT_SUPPORTED;
        }