http://bugs.winehq.org/show_bug.cgi?id=59722 Bug ID: 59722 Summary: RemoveDirectoryW fails with ERROR_SHARING_VIOLATION after subprocess exit Product: Wine Version: 11.8 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: kernel32 Assignee: wine-bugs@list.winehq.org Reporter: joel@airwebreathe.org.uk Distribution: --- Created attachment 80868 --> http://bugs.winehq.org/attachment.cgi?id=80868 reproducer.c (Found by AI testing) After a subprocess exits that had its current working directory set to a given directory, `RemoveDirectoryW()` on that directory fails with `ERROR_SHARING_VIOLATION` (error code 32). Wine does not properly release the directory handle that was used as the subprocess's CWD after the process terminates. On real Windows, removing the directory succeeds immediately after the subprocess exits. ## Impact on MSYS2 The MSYS2/Cygwin runtime maps `ERROR_SHARING_VIOLATION` to `EBUSY` (errno 16). Many MSYS2 test suite tests create a temporary directory, `fork()` + `exec()` a child process (which inherits the CWD), wait for the child to exit, then call `rmdir()` to clean up. Under Wine, this cleanup fails with `EBUSY`, causing the test harness to report failures even though the actual test logic passed. Affected tests include: | Test | Symptom | |------|---------| | fcntl07 | All 2 test cases PASS, but cleanup rmdir fails with EBUSY | | fcntl07B | Test case PASSES, but cleanup rmdir fails with EBUSY | ## Reproducer ``` x86_64-w64-mingw32-gcc -o reproducer.exe reproducer.c -lntdll wine reproducer.exe ``` ### Expected output (real Windows) ``` === Test 3: rmdir after subprocess with CWD in target dir === PASS: CreateDirectory PASS: RemoveDirectory after subprocess exit ``` ### Actual output (Wine 11.4) ``` === Test 3: rmdir after subprocess with CWD in target dir === PASS: CreateDirectory FAIL: RemoveDirectory after subprocess exit (GetLastError=32) Error: 32 ``` Error 32 is `ERROR_SHARING_VIOLATION`, indicating Wine still holds an internal reference to the directory after the subprocess has exited. ## Analysis When Wine creates a process with a CWD in a target directory, it opens a handle to that directory. When the process exits, Wine should close this handle so that the directory is no longer held open. Instead, the handle appears to leak or be released asynchronously, causing an immediate `RemoveDirectoryW` to hit a sharing violation. The underlying NT status is `STATUS_SHARING_VIOLATION`, which occurs because the directory still has an open handle without compatible sharing modes. ## Environment - Wine: 11.4 - Host: Linux x86_64 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.