g-os_lib.adb (Copy_File): Make sure that if From has an Invalid_FD, then we close...
authorRobert Dewar <dewar@adacore.com>
Fri, 17 Feb 2006 16:07:10 +0000 (17:07 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Fri, 17 Feb 2006 16:07:10 +0000 (17:07 +0100)
2006-02-17  Robert Dewar  <dewar@adacore.com>

* g-os_lib.adb (Copy_File): Make sure that if From has an Invalid_FD,
then we close To if it is valid.

From-SVN: r111188

gcc/ada/g-os_lib.adb

index dbfc6b9174538db099fc407bd53eaa5bc1e10883..c1efa039092960f58324c670f03f9336ee48a8e6 100644 (file)
@@ -384,7 +384,14 @@ package body GNAT.OS_Lib is
          procedure Free is new Unchecked_Deallocation (Buf, Buf_Ptr);
 
       begin
+         --  Check for invalid descriptors, making sure that we do not
+         --  accidentally leave an open file descriptor around.
+
          if From = Invalid_FD then
+            if To /= Invalid_FD then
+               Close (To, Status_To);
+            end if;
+
             raise Copy_Error;
 
          elsif To = Invalid_FD then