diff mbox

[Ada] File descriptors leaking

Message ID 20160418124459.GA133683@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 18, 2016, 12:44 p.m. UTC
Two file descriptors are never closed when invoking Non_Blocking_Spawn version
with String parameters Stdout_File and Stderr_File. They are now closed.

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-04-18  Vincent Celier  <celier@adacore.com>

	* s-os_lib.adb (Non_Blocking_Spawn, version with Stdout_File and
	Stderr_File): Close local file descriptors when no longer needed.
diff mbox

Patch

Index: s-os_lib.adb
===================================================================
--- s-os_lib.adb	(revision 235093)
+++ s-os_lib.adb	(working copy)
@@ -1867,6 +1867,14 @@ 
 
       Result := Non_Blocking_Spawn (Program_Name, Args);
 
+      --  Close the files just created for the output, as the file descriptors
+      --  cannot be used anywhere, being local values. It is safe to do that,
+      --  as the file descriptors have been duplicated to form standard output
+      --  and standard error of the spawned process.
+
+      Close (Stdout_FD);
+      Close (Stderr_FD);
+
       --  Restore the standard output and error
 
       Dup2 (Saved_Output, Standout);