Fix possible memory leak condition in PPM for Tizen Platform.
authorJamal Haidar <jamal.haidar@samsung.com>
Tue, 16 Jun 2015 11:27:39 +0000 (16:57 +0530)
committerUze Choi <uzchoi@samsung.com>
Fri, 19 Jun 2015 08:55:54 +0000 (08:55 +0000)
API app_get_id allocates memory internally, which was not freed
resulting in possible memory leak.

Change-Id: I513bda2dbb407eedd9e855703188eab180974122
Signed-off-by: Jamal Haidar <jamal.haidar@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1281
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Harish Marappa <h.marappa@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/protocol-plugin/plugin-manager/src/PluginManager.cpp

index 18c6101..16a861b 100644 (file)
@@ -33,16 +33,18 @@ using namespace OIC;
 PluginManager::PluginManager()
 {
 #ifdef __TIZEN__
-    char *app_id = (char *)malloc(PATH_MAX_SIZE * sizeof(char));
-    char completePath[PATH_MAX_SIZE];
+    char *app_id = NULL;
+    std::string completePath = "";
     int res = app_get_id(&app_id);
     if (APP_ERROR_NONE == res)
     {
-        strcpy(completePath, "/opt/usr/apps/");
-        strcat(completePath, app_id);
-        strcat(completePath, "/lib/libpmimpl.so");
+        completePath = "/opt/usr/apps/";
+        completePath += app_id;
+        completePath += "/lib/libpmimpl.so";
     }
-    handle = dlopen(completePath, RTLD_LAZY);
+    free(app_id);
+    app_id = NULL;
+    handle = dlopen(completePath.c_str(), RTLD_LAZY);
 #else
     handle = dlopen("./libpmimpl.so", RTLD_LAZY);
 #endif //#ifdef __TIZEN__
@@ -87,4 +89,4 @@ std::vector<Plugin> PluginManager::getPlugins(void)
 std::string PluginManager::getState(const std::string plugID)
 {
     return pluginManagerImpl->getState(plugID);
-}
\ No newline at end of file
+}