Results 1 to 1 of 1

Thread: cl.hpp resource leaks (memory leaks) (but not too important).

Threaded View

  1. #1
    Newbie
    Join Date
    Dec 2013
    Posts
    2

    cl.hpp resource leaks (memory leaks) (but not too important).

    In some places cl.hpp file the vector assignment has been used (for example in createKernels method or getSubDevices). In cl::Program::createKernels method I found trivial bug (caused by using wrong type in temporary array).
    Ofcourse a retaining and releasing works properly, however a vector assignment (with type promotions using operator=) generates extraneous reference count if array of objects will be assigned.
    Because temporary array is allocated with using alloca (not with new operator) and this is array of cl::Kernel (not cl_kernel_id) objects, extranenous references will not be released.
    Final reason of resource leaks is cl::Kernel in temporary array (should be cl_kernel) causes resource leaks.

    Relevant code from cl.hpp:
    Code :
    cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
        {
            cl_uint numKernels;
            cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
            if (err != CL_SUCCESS) {
                return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
            }
     
            Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
            /* ^ SHOULD BE cl_kernel* value = (cl_kernel*)alloca( ... */
            err = ::clCreateKernelsInProgram(
                object_, numKernels, (cl_kernel*) value, NULL);
            if (err != CL_SUCCESS) {
                return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
            }
            kernels->assign(&value[0], &value[numKernels]);
            /* how to fix use new operator or release manually with clReleaseKernel */
            return CL_SUCCESS;
        }

    Regards matszpk

    Sorry for my english, I am still learning.

    EDIT: Sorry for first version of the post: I wrote post quickly without considering real reason of a resource leak.
    Finally reason is wrong type of temporary array in createKernels method. Ofcourse assignment of raw OpenCL ids works properly
    and will not causes potential resource leaks.
    Last edited by matszpk; 12-31-2013 at 07:51 AM. Reason: fixing and extends a explanation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •