message: samples: fix OpenCL events leaks
diff: @@ -468,7 +468,6 @@ private:
  cl_kernel m_kernelImg;
  cl_mem m_img_src; // used as src in case processing of cl image
  cl_mem m_mem_obj;
  - cl_event m_event;
  };
  @@ -498,7 +497,6 @@ App::App(CommandLineParser& cmd)
  m_kernelImg = 0;
  m_img_src = 0;
  m_mem_obj = 0;
  - m_event = 0;
  } // ctor
  @@ -529,11 +527,6 @@ App::~App()
  m_mem_obj = 0;
  }
  - if (m_event)
  - {
  - clReleaseEvent(m_event);
  - }
  -
  if (m_kernelBuf)
  {
  clReleaseKernel(m_kernelBuf);
  @@ -775,11 +768,13 @@ int App::process_frame_with_open_cl(cv::Mat& frame, bool use_buffer, cl_mem* mem
  size_t origin[] = { 0, 0, 0 };
  size_t region[] = { (size_t)frame.cols, (size_t)frame.rows, 1 };
  - res = clEnqueueCopyImage(m_queue, m_img_src, mem, origin, origin, region, 0, 0, &m_event);
  + cl_event asyncEvent = 0;
  + res = clEnqueueCopyImage(m_queue, m_img_src, mem, origin, origin, region, 0, 0, &asyncEvent);
  if (CL_SUCCESS != res)
  return -1;
  - res = clWaitForEvents(1, &m_event);
  + res = clWaitForEvents(1, &asyncEvent);
  + clReleaseEvent(asyncEvent);
  if (CL_SUCCESS != res)
  return -1;
  @@ -795,17 +790,15 @@ int App::process_frame_with_open_cl(cv::Mat& frame, bool use_buffer, cl_mem* mem
  }
  }
  - m_event = clCreateUserEvent(m_context, &res);
  - if (0 == m_event || CL_SUCCESS != res)
  - return -1;
  -
  // process left half of frame in OpenCL
  size_t size[] = { (size_t)frame.cols / 2, (size_t)frame.rows };
  - res = clEnqueueNDRangeKernel(m_queue, kernel, 2, 0, size, 0, 0, 0, &m_event);
  + cl_event asyncEvent = 0;
  + res = clEnqueueNDRangeKernel(m_queue, kernel, 2, 0, size, 0, 0, 0, &asyncEvent);
  if (CL_SUCCESS != res)
  return -1;
  - res = clWaitForEvents(1, &m_event);
  + res = clWaitForEvents(1, &asyncEvent);
  + clReleaseEvent(asyncEvent);
  if (CL_SUCCESS != res)
  return -1;
  