summaryrefslogtreecommitdiff
path: root/src/clpp11.hpp
diff options
context:
space:
mode:
authorIvan Shapovalov <intelfx@intelfx.name>2017-01-14 04:22:09 +0300
committerIvan Shapovalov <intelfx@intelfx.name>2017-01-24 02:42:59 +0300
commita9914ee3a834c23abfa7c994a43719f85285edf5 (patch)
tree1025dbb51d965219ff97e36f70d749a9370fbf11 /src/clpp11.hpp
parent8e1c084c9329fe1842e9a3eeeaa46248dec460a5 (diff)
src/clpp11.hpp: check pointers before clRelease*()
This is to avoid spurious "induced" errors on destruction, if construction failed for some reason.
Diffstat (limited to 'src/clpp11.hpp')
-rw-r--r--src/clpp11.hpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/clpp11.hpp b/src/clpp11.hpp
index d73c57be..c984661c 100644
--- a/src/clpp11.hpp
+++ b/src/clpp11.hpp
@@ -333,7 +333,10 @@ class Context {
// Regular constructor with memory management
explicit Context(const Device &device):
- context_(new cl_context, [](cl_context* c) { CheckErrorDtor(clReleaseContext(*c)); delete c; }) {
+ context_(new cl_context, [](cl_context* c) {
+ if (*c) { CheckErrorDtor(clReleaseContext(*c)); }
+ delete c;
+ }) {
auto status = CL_SUCCESS;
const cl_device_id dev = device();
*context_ = clCreateContext(nullptr, 1, &dev, nullptr, nullptr, &status);
@@ -362,7 +365,10 @@ class Program {
// Source-based constructor with memory management
explicit Program(const Context &context, const std::string &source):
- program_(new cl_program, [](cl_program* p) { CheckErrorDtor(clReleaseProgram(*p)); delete p; }) {
+ program_(new cl_program, [](cl_program* p) {
+ if (*p) { CheckErrorDtor(clReleaseProgram(*p)); }
+ delete p;
+ }) {
const char *source_ptr = &source[0];
size_t length = source.length();
auto status = CL_SUCCESS;
@@ -371,8 +377,11 @@ class Program {
}
// Binary-based constructor with memory management
- explicit Program(const Device &device, const Context &context, const std::string& binary):
- program_(new cl_program, [](cl_program* p) { CheckErrorDtor(clReleaseProgram(*p)); delete p; }) {
+ explicit Program(const Device &device, const Context &context, const std::string &binary):
+ program_(new cl_program, [](cl_program* p) {
+ if (*p) { CheckErrorDtor(clReleaseProgram(*p)); }
+ delete p;
+ }) {
const char *binary_ptr = &binary[0];
size_t length = binary.length();
auto status1 = CL_SUCCESS;
@@ -435,8 +444,10 @@ class Queue {
// Regular constructor with memory management
explicit Queue(const Context &context, const Device &device):
- queue_(new cl_command_queue, [](cl_command_queue* s) { CheckErrorDtor(clReleaseCommandQueue(*s));
- delete s; }) {
+ queue_(new cl_command_queue, [](cl_command_queue* s) {
+ if (*s) { CheckErrorDtor(clReleaseCommandQueue(*s)); }
+ delete s;
+ }) {
auto status = CL_SUCCESS;
*queue_ = clCreateCommandQueue(context(), device(), CL_QUEUE_PROFILING_ENABLE, &status);
CLError::Check(status, "clCreateCommandQueue");
@@ -660,7 +671,10 @@ class Kernel {
// Regular constructor with memory management
explicit Kernel(const Program &program, const std::string &name):
- kernel_(new cl_kernel, [](cl_kernel* k) { CheckErrorDtor(clReleaseKernel(*k)); delete k; }) {
+ kernel_(new cl_kernel, [](cl_kernel* k) {
+ if (*k) { CheckErrorDtor(clReleaseKernel(*k)); }
+ delete k;
+ }) {
auto status = CL_SUCCESS;
*kernel_ = clCreateKernel(program(), name.c_str(), &status);
CLError::Check(status, "clCreateKernel");