mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
aed41fdabe
core(opengl): fix memory leak in OpenCL extensions gathering #28981 ## Problem Fixes #28980 In `modules/core/src/opengl.cpp`, inside `initializeContextFromGL()`, a `char[]` buffer is allocated to query OpenCL device extensions: ```cpp extensions = new char[extensionSize]; status = clGetDeviceInfo(..., extensions, &extensionSize); if (status != CL_SUCCESS) continue; // leaks `extensions` ``` When `clGetDeviceInfo()` fails, `continue` skips the corresponding `delete[]` on the success path, causing the allocated buffer to leak. Additionally, the `catch (...)` block also bypasses cleanup, so any thrown exception leaks the buffer as well. ## Fix Replace the raw `char*` allocation with `std::unique_ptr<char[]>`. This ensures the buffer is automatically released on all exit paths, including: - normal execution - early `continue` - exception handling paths ## Checklist - [x] I agree to contribute to the project under the Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on code under GPL or another license incompatible with OpenCV. - [x] The PR is proposed to the proper branch (`4.x`). - [x] There is a reference to the original bug report and related work, if applicable. - [x] Accuracy/performance tests and test data in `opencv_extra` are included, if applicable. - [x] The feature/change is documented and sample code can be built with the project CMake configuration, if applicable.