From 20b9529bc309f9ef63a4ad4f17421aa25ef9c95c Mon Sep 17 00:00:00 2001 From: Sewon Ahn Date: Sun, 20 Sep 2026 18:32:17 +0900 Subject: [PATCH] core: fix memory leak in glob()'s readdir() on WinRT/_WIN32_WCE readdir() allocates a new buffer for dir->ent.d_name on every call and overwrites the previous pointer without freeing it. Since cv::glob() calls readdir() once per directory entry, every call except the last leaks its allocation. Under _WIN32_WCE, DIR has no destructor at all, so every allocation leaks, including the last one. --- modules/core/src/glob.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/core/src/glob.cpp b/modules/core/src/glob.cpp index 03638d49b1..fc83d64484 100644 --- a/modules/core/src/glob.cpp +++ b/modules/core/src/glob.cpp @@ -66,7 +66,7 @@ namespace #endif HANDLE handle; dirent ent; -#ifdef WINRT +#if defined(WINRT) || defined(_WIN32_WCE) DIR() { } ~DIR() { @@ -113,6 +113,7 @@ namespace char* aname = new char[asize+1]; aname[asize] = 0; wcstombs(aname, dir->data.cFileName, asize); + delete[] dir->ent.d_name; dir->ent.d_name = aname; #else if (dir->ent.d_name != 0)