[AWS] Possible leak found in aws-smtp-client.adb

Thomas Løcke thomas.granvej6 at gmail.com
Wed Jun 22 15:46:53 CEST 2011


I'm calling AWS.SMTP.Client.Send to send an email:

    declare

       Server  : AWS.SMTP.Receiver;

    begin
       Server := AWS.SMTP.Client.Initialize
         (Server_Name => "localhost",
          Port        => 25);

       AWS.SMTP.Client.Send (Server => Server,
                                            From   => From,
                                            To     => Recipients,
                                            Subject => "Test",
                                            Message => "Top of the world!",
                                            Status => Status);

    exception
       when others =>
          Ada.Text_IO.Put_Line ("Trouble!");

    end;

And that works flawlessly, with no leaks at all, as long as there's a
functional SMTP server running at localhost.

But if I shutdown the SMTP server, the code starts to leak. On each
and every call to Send, 48 bytes are leaked, so calling it 1000 times
results in 48_000 leaked bytes. Nasty!

Here's the valgrind output:

    ==16987== 48 bytes in 1 blocks are definitely lost in loss record 139 of 212
    ==16987==    at 0x4C26F0E: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==16987==    by 0x7421D7: __gnat_malloc (in
/home/thomas/Ada/yolk/demo/exe/yolk_demo)
    ==16987==    by 0x57ECA7: aws__net__socket__2 (in
/home/thomas/Ada/yolk/demo/exe/yolk_demo)
    ==16987==    by 0x4E4183: aws__smtp__client__open (in
/home/thomas/Ada/yolk/demo/exe/yolk_demo)
    ==16987==    by 0x4E4865: aws__smtp__client__send__4 (in
/home/thomas/Ada/yolk/demo/exe/yolk_demo)
    ==16987==    by 0x47900F: yolk__email__composer__send (in
/home/thomas/Ada/yolk/demo/exe/yolk_demo)

>From a quick glance at the AWS code, it seems that everything is freed
properly, but since my Ada/AWS foo is still weak, I might've missed
something. I doubt that the leak originates in my own code, as what
I'm doing really is as simple as the example posted above. I
initialize an SMTP server, call Send and do some simple output if an
exception is raised. All done in a block, as shown.

The program has been compiled with GNAT GPL 2010 and the following parameters:

    for Default_Switches ("Ada")
      use ("-gnatwa",
             "-gnata",
             "-gnatVa",
             "-gnaty3abcdefhiklmnoprstux",
             "-Wall",
             "-O1",
             "-gnat05",
             "-g");

And valgrind is called like this:

    valgrind -v --leak-check=full --track-origins=yes yolk_demo

I'm at my wits end.

Sincerely,
Thomas Løcke

ps. I've tried this with the latest official AWS 2011 package and with
the latest dev commit d4538275d0dab54f8596f777d20bc999e6af6420. Same
result.


More information about the AWS mailing list