Fix issues shown by cppcheck for wrt-plugins-common
[platform/framework/web/wrt-plugins-common.git] / src / plugins-installer / plugin_installer.cpp
index 05475d2..824f6b9 100644 (file)
@@ -377,22 +377,26 @@ int PluginsInstaller::installAllPlugins()
     }
 
     LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
-    struct dirent* libdir;
+    int return_code;
+    struct dirent libdir;
+    struct dirent* result;
 
     errno = 0;
 
     std::list<std::string> pluginsPaths;
 
-    while ((libdir = readdir(dir)) != 0) {
-        if (strcmp(libdir->d_name, ".") == 0 ||
-            strcmp(libdir->d_name, "..") == 0)
+    for (return_code = readdir_r(dir, &libdir, &result);
+            result != NULL && return_code != 0;
+            return_code = readdir_r(dir, &libdir, &result)) {
+        if (strcmp(libdir.d_name, ".") == 0 ||
+            strcmp(libdir.d_name, "..") == 0)
         {
             continue;
         }
 
         std::string path = PLUGIN_PATH;
         path += "/";
-        path += libdir->d_name;
+        path += libdir.d_name;
 
         struct stat tmp;
 
@@ -410,6 +414,9 @@ int PluginsInstaller::installAllPlugins()
         pluginsPaths.push_back(path);
     }
 
+    if (0 != return_code)
+        LogError("Error while reading directory.");
+
     if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
         LogError("Failed to close dir: " << PLUGIN_PATH);
     }