diff mbox series

[Ada] Fix memory leak in GNAT.Expect.Non_Blocking_Spawn on Windows

Message ID 20201216131535.GA70025@adacore.com
State New
Headers show
Series [Ada] Fix memory leak in GNAT.Expect.Non_Blocking_Spawn on Windows | expand

Commit Message

Pierre-Marie de Rodat Dec. 16, 2020, 1:15 p.m. UTC
It is not leaking on Linux because the memory heap is reinitialized when
the new executable is loaded into the child process after calling fork.

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

gcc/ada/

	* libgnat/g-expect.adb (Non_Blocking_Spawn): Deallocate elements
	on Arg_List after calling Set_Up_Child_Communications.
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/g-expect.adb b/gcc/ada/libgnat/g-expect.adb
--- a/gcc/ada/libgnat/g-expect.adb
+++ b/gcc/ada/libgnat/g-expect.adb
@@ -1181,6 +1181,12 @@  package body GNAT.Expect is
          Set_Up_Child_Communications
            (Descriptor, Pipe1, Pipe2, Pipe3, Command_With_Path.all,
             C_Arg_List'Address);
+
+         --  On Windows systems we need to release memory taken for Arg_List
+
+         for A of Arg_List loop
+            Free (A);
+         end loop;
       end if;
 
       Free (Command_With_Path);