Browse Source

For safety: Invalidate handle first, then Close handle

Martin 1 year ago
parent
commit
ab2e02cc58
1 changed files with 2 additions and 2 deletions
  1. 2 2
      packages/fcl-process/src/processbody.inc

+ 2 - 2
packages/fcl-process/src/processbody.inc

@@ -1066,9 +1066,9 @@ begin
      exit;
   H:=OurHandle;
   // Writeln(StdErr, GetProcessID ,' : ',ProcessHandleType,' closing our handle ',IOType,': ',FOurHandle);
+  FOurHandle:=THandle(INVALID_HANDLE_VALUE) ;
   if H<>THandle(INVALID_HANDLE_VALUE) then
     FileClose(H);
-  FOurHandle:=THandle(INVALID_HANDLE_VALUE) ;
 end;
 
 procedure TIODescriptor.CloseTheirHandle(aForceClose: Boolean);
@@ -1082,10 +1082,10 @@ begin
      exit;
   H:=ResolveProcessHandle;
   // Writeln(StdErr,GetProcessID,' : ',ProcessHandleType,' closing their handle ',IOType,': ',H);
+  FTheirHandle:=THandle(INVALID_HANDLE_VALUE);
   if H<>THandle(INVALID_HANDLE_VALUE) then
     begin
     FileClose(H);
-    FTheirHandle:=THandle(INVALID_HANDLE_VALUE);
     end;
 end;