Use member variable to remain dlopen handle (#4534)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 4 Mar 2019 04:21:56 +0000 (13:21 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 4 Mar 2019 04:21:56 +0000 (13:21 +0900)
Use member variable to avoid warning by handle lost without dlclose()

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
libs/ARMComputeEx/arm_compute/core/CL/OpenCLEx.h
libs/ARMComputeEx/src/core/CL/OpenCLEx.cpp

index dbda354..c0fc615 100644 (file)
@@ -47,6 +47,10 @@ private:
   void load_symbols(void *handle);
 
 public:
+  /**
+   * @brief Destroy the CLSymbolsEx object
+   */
+  ~CLSymbolsEx();
   /** Get the static instance of CLSymbols.
    *
    * @return The static instance of CLSymbols.
@@ -74,6 +78,7 @@ public:
 
 private:
   std::pair<bool, bool> _loaded{false, false};
+  void *_handle{nullptr};
 };
 } // namespace arm_compute
 #endif /* __ARM_COMPUTE_OPENCLEX_H__ */
index cbda169..24e96e7 100644 (file)
 
 namespace arm_compute
 {
+
+CLSymbolsEx::~CLSymbolsEx()
+{
+  if (_handle != nullptr)
+  {
+    dlclose(_handle);
+  }
+}
+
 CLSymbolsEx &CLSymbolsEx::get()
 {
   static CLSymbolsEx symbols;
@@ -85,6 +94,9 @@ bool CLSymbolsEx::load(const std::string &library)
   // Disable default loading and set status to successful
   _loaded = std::make_pair(true, true);
 
+  // Workaround to avoid warning by handle lost without dlclose()
+  _handle = handle;
+
   return true;
 }