mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 20:50:25 +08:00
use new instead of malloc and guard it
This commit is contained in:
parent
50f6d54f87
commit
4cbb96b396
@ -1681,14 +1681,27 @@ Context& initializeContextFromGL()
|
|||||||
|
|
||||||
if(extensionSize > 0)
|
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);
|
status = clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, extensionSize, extensions, &extensionSize);
|
||||||
if (status != CL_SUCCESS)
|
if (status != CL_SUCCESS)
|
||||||
continue;
|
continue;
|
||||||
|
} catch(std::exception& ex) {
|
||||||
|
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device extensions gathering");
|
||||||
|
}
|
||||||
|
|
||||||
std::string devString(extensions);
|
std::string devString;
|
||||||
free(extensions);
|
|
||||||
|
|
||||||
|
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 oldPos = 0;
|
||||||
size_t spacePos = devString.find(' ', oldPos); // extensions string is space delimited
|
size_t spacePos = devString.find(' ', oldPos); // extensions string is space delimited
|
||||||
@ -1710,8 +1723,7 @@ Context& initializeContextFromGL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sharingSupported)
|
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
|
// Define OS-specific context properties and create the OpenCL context
|
||||||
#if defined (__APPLE__)
|
#if defined (__APPLE__)
|
||||||
|
Loading…
Reference in New Issue
Block a user