Files
opencv-MIRROR/modules/core/src
Sewon Ahn 62751db0d7 Merge pull request #30005 from lrycro:fix/glob-readdir-leak
core: fix memory leak in glob()'s readdir() on WinRT/_WIN32_WCE - #30005

## Problem

Fixes #30004

In `modules/core/src/glob.cpp`, the WinRT/`_WIN32_WCE` implementation of `readdir()` allocates a new buffer for `dir->ent.d_name` on every call and overwrites the previous pointer without freeing it:

```cpp
char* aname = new char[asize+1];
...
dir->ent.d_name = aname;
```

`cv::glob()` calls `readdir()` once per directory entry, so every call except the last leaks its allocation. Additionally, the `DIR` destructor that releases `d_name` was gated by `#ifdef WINRT` only, so `_WIN32_WCE` builds leaked every allocation, including the last one.

## Fix

- Free the previous `dir->ent.d_name` before overwriting it in `readdir()`, matching how `~DIR()` already frees it on WinRT.
- Extend the `DIR` destructor guard from `#ifdef WINRT` to `#if defined(WINRT) || defined(_WIN32_WCE)` so the final buffer is also released under `_WIN32_WCE`.

## 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.
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable.
- [x] The feature is well documented and sample code can be built with the project CMake.

Thanks for reviewing.
2026-09-21 18:07:13 +03: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
2026-09-11 15:33:26 +03: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
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
2014-08-15 12:09:16 +04:00
2026-09-07 21:44:04 -07:00