coverity error handling 59/178859/8
authorGuneet K <g.khosla@samsung.com>
Mon, 14 May 2018 09:42:22 +0000 (15:12 +0530)
committerjaekuk lee <juku1999@samsung.com>
Tue, 15 May 2018 06:14:47 +0000 (06:14 +0000)
This patch makes handle_ a data member of XWalkExtension class.
dlclose(handle_) is called from XWalkExtension class destructor
to prevent resource leak.

Coverity:109521

Change-Id: I24ae7763809536b3b5ad486c7f45c7c40a9dc528
Signed-off-by: Guneet K <g.khosla@samsung.com>
extensions/common/xwalk_extension.cc
extensions/common/xwalk_extension.h

index a5f92929e59e78e6456a7c5b300e6b206f01e07a..f1ecfa53120b9930a45000da3c99b59cf3051778 100755 (executable)
@@ -20,6 +20,7 @@ XWalkExtension::XWalkExtension(const std::string& path,
     library_path_(path),
     xw_extension_(0),
     lazy_loading_(false),
+    handle_(nullptr),
     delegate_(delegate),
     created_instance_callback_(NULL),
     destroyed_instance_callback_(NULL),
@@ -39,6 +40,7 @@ XWalkExtension::XWalkExtension(const std::string& path,
     name_(name),
     entry_points_(entry_points),
     lazy_loading_(true),
+    handle_(nullptr),
     delegate_(delegate),
     created_instance_callback_(NULL),
     destroyed_instance_callback_(NULL),
@@ -54,25 +56,26 @@ XWalkExtension::~XWalkExtension() {
   if (shutdown_callback_)
     shutdown_callback_(xw_extension_);
   XWalkExtensionAdapter::GetInstance()->UnregisterExtension(this);
+  dlclose(handle_);
 }
 
 bool XWalkExtension::Initialize() {
   if (initialized_)
     return true;
 
-  void* handle = dlopen(library_path_.c_str(), RTLD_LAZY);
-  if (!handle) {
+  handle_ = dlopen(library_path_.c_str(), RTLD_LAZY);
+  if (!handle_) {
     LOGGER(ERROR) << "Error loading extension '"
                   << library_path_ << "' : " << dlerror();
     return false;
   }
 
   XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>(
-      dlsym(handle, "XW_Initialize"));
+      dlsym(handle_, "XW_Initialize"));
   if (!initialize) {
     LOGGER(ERROR) << "Error loading extension '" << library_path_
                   << "' : couldn't get XW_Initialize function.";
-    dlclose(handle);
+    dlclose(handle_);
     return false;
   }
 
@@ -84,7 +87,7 @@ bool XWalkExtension::Initialize() {
   if (ret != XW_OK) {
     LOGGER(ERROR) << "Error loading extension '" << library_path_
                   << "' : XW_Initialize() returned error value.";
-    dlclose(handle);
+    dlclose(handle_);
     return false;
   }
 
index c7aaf8300a068ae6aba247a50f1d69c1193ad52a..6b19630ed2da084ed485040fecc11b66dc4c0310 100755 (executable)
@@ -66,6 +66,7 @@ class XWalkExtension {
   std::string javascript_api_;
   StringVector entry_points_;
   bool lazy_loading_;
+  void *handle_;
 
   XWalkExtensionDelegate* delegate_;