TFileStream.Destroy fails to free the file handle, blocking any further access to that file if Handle was 4
Original Reporter info from Mantis: chebmaster
-
Reporter name:
Original Reporter info from Mantis: chebmaster
- Reporter name:
Description:
Happens when Handle is 4 because of the following code in RTL:
Procedure FileClose (Handle : THandle);
begin
if Handle<=4 then
exit;
CloseHandle(Handle);
end;
Due to this, when I try to close a file then open it later again, my program crashes.
Steps to reproduce:
var s: TFileStream;
s:= TFileStream.Create(FileName, fmOpenReadWrite);
//Check here if s.Handle is 4. Annoyingly, it is.
s.Free;
s:=TFileStream.Create(FileName, fmOpenReadWrite); //this one fails;
s.Free;
Happens when I run my application from any terminal emulator using any of the following lines:
wine ./myexe.exe
./myexe.exe
Never happens when I run my application from any file manager (gnome commander, midnight commander, wine explorer.exe and so on)
Additional information:
May be other factors at work as my game engine performs many other operations at startup, including opening kernel32.dll for read to detect Wine by its signature string.
Mantis conversion info:
- Mantis ID: 27221
- OS: Wine
- OS Build: various
- Platform: Win32
- Version: 2.6.4
- Fixed in revision: 38189 (#19b47e54)