Following this question, I'm trying to compile and test this GitHub Gist. But I get heap memory corruption error at runtime:
Microsoft Visual C++ Runtime Library Debug Error! Program: ... HEAP CORRUPTION DTECTED: after Normal block ... at ... CRT detected that the application wrote to memory after the end of heap buffer (Press Retry to debug the application)
But when pressing Retry
as instructed the program seem to finish successfully with no erros/warnings or unexpected outputs.
A brief version of the main.c
code:
#define CL_TARGET_OPENCL_VERSION 120
#include <CL/cl.h>
#include <stdio.h>
#include <stdlib.h> // exit, EXIT_FAILURE
int main(int argc, char const *argv[])
{
cl_int err;
cl_uint numPlatforms = 0;
cl_platform_id *platforms;
err = clGetPlatformIDs(0, NULL, &numPlatforms);
platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * numPlatforms);
cl_uint *numDevices = (cl_uint *)malloc(sizeof(cl_uint) * numPlatforms);
cl_device_id **devices = (cl_device_id **)malloc(sizeof(cl_device_id **) * numPlatforms);
for (size_t i = 0; i < numPlatforms; i++)
{
err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices[i]);
devices[i] = (cl_device_id *)malloc(sizeof(cl_device_id *) * numDevices[i]);
for (size_t j = 0; j < numDevices[i]; j++)
{
err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, numDevices[i], (devices[i] + j), NULL);
}
free(devices[i]);
}
free(devices);
free(numDevices);
free(platforms);
return 0;
}
I would appreciate it if you could help me know what is the problem and how I can resolve it.