From 90aaac9dba1a20a9314db59dc82af61bc0b4a912 Mon Sep 17 00:00:00 2001 From: qorexdevs Date: Thu, 23 Apr 2026 18:41:06 +0500 Subject: [PATCH] Replace realloc with std::vector in IOThreadProc The raw realloc calls in Process::IOThreadProc() are replaced with std::vector, which handles resizing and cleanup automatically. Also fixes a minor memory leak since the old pointers were never freed. refs #10813 --- AUTHORS | 1 + lib/base/process.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 32938a9800a..55abc4fbc5d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -249,6 +249,7 @@ Phil Hutchinson Philipp Dallig Philipp Dorschner pv2b +qorexdevs Ralph Breier Reto Zeder Ricardo Bartels diff --git a/lib/base/process.cpp b/lib/base/process.cpp index e2b8922c8ab..eb40b1a0fd5 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -597,10 +597,10 @@ bool Process::GetAdjustPriority() const void Process::IOThreadProc(int tid) { #ifdef _WIN32 - HANDLE *handles = nullptr; - HANDLE *fhandles = nullptr; + std::vector handles; + std::vector fhandles; #else /* _WIN32 */ - pollfd *pfds = nullptr; + std::vector pfds; #endif /* _WIN32 */ int count = 0; double now; @@ -617,13 +617,13 @@ void Process::IOThreadProc(int tid) count = 1 + l_Processes[tid].size(); #ifdef _WIN32 - handles = reinterpret_cast(realloc(handles, sizeof(HANDLE) * count)); - fhandles = reinterpret_cast(realloc(fhandles, sizeof(HANDLE) * count)); + handles.resize(count); + fhandles.resize(count); fhandles[0] = l_Events[tid]; #else /* _WIN32 */ - pfds = reinterpret_cast(realloc(pfds, sizeof(pollfd) * count)); + pfds.resize(count); pfds[0].fd = l_EventFDs[tid][0]; pfds[0].events = POLLIN; @@ -670,9 +670,9 @@ void Process::IOThreadProc(int tid) timeout *= 1000; #ifdef _WIN32 - DWORD rc = WaitForMultipleObjects(count, fhandles, FALSE, timeout == -1 ? INFINITE : static_cast(timeout)); + DWORD rc = WaitForMultipleObjects(count, fhandles.data(), FALSE, timeout == -1 ? INFINITE : static_cast(timeout)); #else /* _WIN32 */ - int rc = poll(pfds, count, timeout); + int rc = poll(pfds.data(), count, timeout); if (rc < 0) continue;