Skip to content

Commit 4cbb96b

Browse files
author
kallaballa
committed
use new instead of malloc and guard it
1 parent 50f6d54 commit 4cbb96b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

modules/core/src/opengl.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,14 +1681,27 @@ Context& initializeContextFromGL()
16811681

16821682
if(extensionSize > 0)
16831683
{
1684-
char* extensions = (char*)malloc(extensionSize);
1685-
status = clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, extensionSize, extensions, &extensionSize);
1686-
if (status != CL_SUCCESS)
1687-
continue;
1684+
char* extensions = nullptr;
16881685

1689-
std::string devString(extensions);
1690-
free(extensions);
1686+
try {
1687+
extensions = new char[extensionSize];
16911688

1689+
status = clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, extensionSize, extensions, &extensionSize);
1690+
if (status != CL_SUCCESS)
1691+
continue;
1692+
} catch(std::exception& ex) {
1693+
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device extensions gathering");
1694+
}
1695+
1696+
std::string devString;
1697+
1698+
if(extensions != nullptr) {
1699+
devString = extensions;
1700+
delete[] extensions;
1701+
}
1702+
else {
1703+
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Unexpected error during device extensions gathering");
1704+
}
16921705

16931706
size_t oldPos = 0;
16941707
size_t spacePos = devString.find(' ', oldPos); // extensions string is space delimited
@@ -1710,8 +1723,7 @@ Context& initializeContextFromGL()
17101723
}
17111724

17121725
if (!sharingSupported)
1713-
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: OpenGL sharing not supported: %d", status));
1714-
1726+
continue;
17151727

17161728
// Define OS-specific context properties and create the OpenCL context
17171729
#if defined (__APPLE__)

0 commit comments

Comments
 (0)