2
0
Эх сурвалжийг харах

* TIn/OutputPipeStream gets closed on freeing

git-svn-id: trunk@19652 -
Tomas Hajny 13 жил өмнө
parent
commit
38fca89c69

+ 8 - 0
packages/fcl-process/src/dummy/pipes.inc

@@ -18,6 +18,8 @@
 Function CreatePipeHandles (Var Inhandle,OutHandle : THandle) : Boolean;
 
 begin
+  InHandle := THandle (UnusedHandle);
+  OutHandle := THandle (UnusedHandle);
   Result := False;
 end;
 
@@ -37,3 +39,9 @@ procedure TInputPipeStream.InvalidSeek;
 begin
   Raise EPipeSeek.Create (ENoSeekMsg);
 end;
+
+procedure PipeClose (const FHandle: THandle); inline;
+begin
+  if FHandle <> UnusedHandle then
+   FileClose (FHandle);
+end;

+ 4 - 0
packages/fcl-process/src/os2/pipes.inc

@@ -42,3 +42,7 @@ begin
   Raise EPipeSeek.Create (ENoSeekMsg);
 end;
 
+procedure PipeClose (const FHandle: THandle); inline;
+begin
+  FileClose(FHandle);
+end;

+ 12 - 0
packages/fcl-process/src/pipes.pp

@@ -36,6 +36,7 @@ Type
       function GetPosition: Int64; override;
       procedure InvalidSeek; override;
     public
+      destructor Destroy; override;
       Function Write (Const Buffer; Count : Longint) :Longint; Override;
       function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override;
       Function Read (Var Buffer; Count : Longint) : longint; Override;
@@ -44,6 +45,7 @@ Type
 
   TOutputPipeStream = Class(THandleStream)
     Public
+      destructor Destroy; override;
       function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override;
       Function Read (Var Buffer; Count : Longint) : longint; Override;
     end;
@@ -75,6 +77,11 @@ begin
     Raise EPipeCreation.Create (EPipeMsg)
 end;
 
+destructor TInputPipeStream.Destroy;
+begin
+  ClosePipe (FHandle);
+end;
+
 Function TInputPipeStream.Write (Const Buffer; Count : Longint) : longint;
 
 begin
@@ -100,6 +107,11 @@ begin
   Result:=FPos;
 end;
 
+destructor TOutputPipeStream.Destroy;
+begin
+  ClosePipe (FHandle);
+end;
+
 Function TOutputPipeStream.Read(Var Buffer; Count : Longint) : longint;
 
 begin

+ 0 - 1
packages/fcl-process/src/process.pp

@@ -293,7 +293,6 @@ end;
 procedure TProcess.FreeStream(var AStream: THandleStream);
 begin
   if AStream = nil then exit;
-  FileClose(AStream.Handle);
   FreeAndNil(AStream);
 end;
 

+ 4 - 0
packages/fcl-process/src/unix/pipes.inc

@@ -40,3 +40,7 @@ begin
   Raise EPipeSeek.Create (ENoSeekMsg);
 end;
 
+procedure PipeClose (const FHandle: THandle); inline;
+begin
+  FileClose(FHandle);
+end;

+ 5 - 0
packages/fcl-process/src/win/pipes.inc

@@ -50,3 +50,8 @@ procedure TInputPipeStream.InvalidSeek;
 begin
   Raise EPipeSeek.Create (ENoSeekMsg);
 end;
+
+procedure PipeClose (const FHandle: THandle); inline;
+begin
+  FileClose(FHandle);
+end;