Files
opencv-MIRROR/modules/core/src
Srujan rai aed41fdabe Merge pull request #28981 from Srujan-rai:fix/opengl-extensions-memory-leak
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.
2026-06-10 20:26:55 +03:00
..
2025-06-26 14:45:19 +02:00
2024-03-05 12:15:39 +03:00
2018-09-07 20:33:52 +09:00
2019-03-05 14:47:04 +03:00
2022-03-03 07:21:53 +09:00
2019-12-27 12:46:53 +00:00
2024-03-05 12:15:39 +03:00
2025-10-16 21:19:12 +09:00
2024-03-05 12:15:39 +03:00
2025-01-13 16:34:28 +01:00
2025-03-24 09:21:22 +03:00
2026-05-23 10:17:16 +02:00
2025-01-13 16:34:28 +01:00
2021-03-02 23:24:28 +00:00
2018-02-12 14:14:08 +03:00
2018-08-27 14:42:18 +03:00
2026-03-20 13:20:31 +05:30
2014-08-15 12:09:16 +04:00