mirror of
https://github.com/zebrajr/opencv.git
synced 2026-01-15 12:15:17 +00:00
Fix tempfile race condition on Windows (issue #19648) #28087 Fix tempfile race condition on Windows Addresses issue #19648 Problem The cv::tempfile() function on Windows used GetTempFileNameA() followed by an immediate DeleteFileA() call. This created a race condition where multiple OpenCV processes running simultaneously could receive the same temporary filename, leading to name collisions. Root Cause The previous implementation: Called GetTempFileNameA() to generate a temp filename Immediately deleted the file to free the name Returned just the filename string Between steps 2 and 3, another process could call GetTempFileNameA() and receive the same filename, causing a collision. Solution Replaced GetTempFileNameA() with GUID-based filename generation using CoCreateGuid(), following the same approach already used in GetTempFileNameWinRT() and Microsoft's recommendations for scenarios requiring many temp files. Changes modules/core/src/system.cpp: Removed GetTempFileNameA() and DeleteFileA() calls Added CoCreateGuid() to generate unique GUID-based filenames Format: "ocv{GUID}" where GUID ensures uniqueness across processes Benefits Eliminates race condition in multi-process scenarios No file I/O overhead from creating and deleting placeholder files Consistent with WinRT implementation approach Follows Microsoft best practices Testing Standard OpenCV test suite. The change only affects Windows temp file naming and maintains the same String return type and usage pattern.