use new instead of malloc and guard it

This commit is contained in:
kallaballa 2024-10-10 15:14:58 +02:00
parent 50f6d54f87
commit 4cbb96b396

View File

@ -1681,14 +1681,27 @@ Context& initializeContextFromGL()
if(extensionSize > 0)
{
char* extensions = (char*)malloc(extensionSize);
char* extensions = nullptr;
try {
extensions = new char[extensionSize];
status = clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, extensionSize, extensions, &extensionSize);
if (status != CL_SUCCESS)
continue;
} catch(std::exception& ex) {
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device extensions gathering");
}
std::string devString(extensions);
free(extensions);
std::string devString;
if(extensions != nullptr) {
devString = extensions;
delete[] extensions;
}
else {
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Unexpected error during device extensions gathering");
}
size_t oldPos = 0;
size_t spacePos = devString.find(' ', oldPos); // extensions string is space delimited
@ -1710,8 +1723,7 @@ Context& initializeContextFromGL()
}
if (!sharingSupported)
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: OpenGL sharing not supported: %d", status));
continue;
// Define OS-specific context properties and create the OpenCL context
#if defined (__APPLE__)