This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] File descriptor leak in GNAT.Expect

When GNAT.Expect reaches the end of its input, it does not properly
closes the input file descriptor, thus resulting in a memory leak.
This was properly handles when calling Get_Process_Output, but not
when writing the loop manually

--  The following program had errors reported by valgrind (fd leaks)
with Ada.Directories;
with GNAT.Expect;
with GNAT.OS_Lib;

procedure GNAT_Expect is
   File  : constant String := "/tmp/data.expect";
   Count : constant        := 2048;
   Args  : GNAT.OS_Lib.Argument_List (1 .. 4);
   Pd    : GNAT.Expect.Process_Descriptor;
   Match : GNAT.Expect.Expect_Match;
   Cmd   : constant String := "echo testdata > " & File;
   Res   : Integer         := 1;
   Args (1) := new String'("-o");
   Args (2) := new String'("pipefail");
   Args (3) := new String'("-c");
   Args (4) := new String'(Cmd);
   for I in 1 .. Count loop
        (Descriptor  => Pd,
         Command     => "/bin/bash",
         Args        => Args,
         Buffer_Size => 0);
           (Descriptor  => Pd,
            Result      => Match,
            Regexp      => "",
            Timeout     => -1);
         when GNAT.Expect.Process_Died =>
            GNAT.Expect.Close (Descriptor => Pd,
                               Status     => Res);
   end loop;
end GNAT_Expect;

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

2012-04-02  Emmanuel Briot  <>

	* g-expect.adb (Expect_Internal): Fix leak of the input file descriptor.

Attachment: difs
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]