aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2019-07-05 16:03:36 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-07-08 10:48:05 +0000
commit74cd112addebc7678cb763cc1cb173feb0e61bb2 (patch)
tree40524e9fab917bad9dea263e461af856b4f3d97b
parented51650a604e4dc7cc87fdeeefb2b01ad414f699 (diff)
downloadComputeLibrary-74cd112addebc7678cb763cc1cb173feb0e61bb2.tar.gz
COMPMID-2425: Fix memory leak reported by coverity
Change-Id: Ia41626a59148978ea72bee9c5358f2748a29144c Signed-off-by: Michalis Spyrou <michalis.spyrou@arm.com> Reviewed-on: https://review.mlplatform.org/c/1482 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
-rw-r--r--arm_compute/core/CL/OpenCL.h12
-rw-r--r--src/core/CL/OpenCL.cpp10
2 files changed, 21 insertions, 1 deletions
diff --git a/arm_compute/core/CL/OpenCL.h b/arm_compute/core/CL/OpenCL.h
index fc7083d276..fbf603ea00 100644
--- a/arm_compute/core/CL/OpenCL.h
+++ b/arm_compute/core/CL/OpenCL.h
@@ -64,6 +64,17 @@ private:
void load_symbols(void *handle);
public:
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLSymbols(const CLSymbols &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLSymbols &operator=(const CLSymbols &) = delete;
+ /** Allow instances of this class to be move constructed */
+ CLSymbols(CLSymbols &&) = default;
+ /** Allow instances of this class to be moved */
+ CLSymbols &operator=(CLSymbols &&) = default;
+ /** Destructor */
+ ~CLSymbols();
+
/** Get the static instance of CLSymbols.
*
* @return The static instance of CLSymbols.
@@ -138,6 +149,7 @@ public:
private:
std::pair<bool, bool> _loaded{ false, false };
+ void *handle{ nullptr };
};
} // namespace arm_compute
#endif /* __ARM_COMPUTE_OPENCL_H__ */
diff --git a/src/core/CL/OpenCL.cpp b/src/core/CL/OpenCL.cpp
index ef03a5a302..0212774161 100644
--- a/src/core/CL/OpenCL.cpp
+++ b/src/core/CL/OpenCL.cpp
@@ -35,6 +35,14 @@ CLSymbols &CLSymbols::get()
return symbols;
}
+CLSymbols::~CLSymbols()
+{
+ if(handle)
+ {
+ dlclose(handle);
+ }
+}
+
bool CLSymbols::load_default()
{
static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
@@ -61,7 +69,7 @@ bool CLSymbols::load_default()
bool CLSymbols::load(const std::string &library)
{
- void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
+ handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
if(handle == nullptr)
{