mirror of
https://github.com/opencv/opencv.git
synced 2026-01-18 17:21:42 +01:00
2cf9c68da04dd90e29304af78802000f4a0e4c01
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.
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/4.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): http://answers.opencv.org
- Issue tracking: https://github.com/opencv/opencv/issues
- Additional OpenCV functionality: https://github.com/opencv/opencv_contrib
- Donate to OpenCV: https://opencv.org/support/
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.
Additional Resources
- Submit your OpenCV-based project for inclusion in Community Friday on opencv.org
- Subscribe to the OpenCV YouTube Channel featuring OpenCV Live, an hour-long streaming show
- Follow OpenCV on LinkedIn for daily posts showing the state-of-the-art in computer vision & AI
- Apply to be an OpenCV Volunteer to help organize events and online campaigns as well as amplify them
- Follow OpenCV on Mastodon in the Fediverse
- Follow OpenCV on Twitter
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Description
Languages
C++
87.5%
C
3.1%
Python
3%
CMake
2%
Java
1.5%
Other
2.7%