From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec2a500cce3658c4,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: mosteo@gmail.com (Alex R. Mosteo) Newsgroups: comp.lang.ada Subject: Memory leak - What the ...? Date: 10 Oct 2004 14:33:49 -0700 Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 62.101.164.195 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1097444030 11438 127.0.0.1 (10 Oct 2004 21:33:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 10 Oct 2004 21:33:50 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:5013 Date: 2004-10-10T14:33:49-07:00 List-Id: Hi, as the topic says, this post is about some code which leaks. I'm now sure of having trapped the leak, but I don't understand where is my error. The culprit is a controlled type, one of whose members is an access to a Stream_Element_Array. The idea is to have an array of the exact length required and not a worst case one, without using an unconstrained type. Platform is gnat 3.15p, compiling with assertions enabled (-gnata), either win32 or linux. Running a lot of tests with gnatmem, it always shows the allocation not deallocated being at: s-assert.adb:46 system.assertions.raise_assert_failure adagio-g2-transceiver_types.adb:134 adagio.g2.transceiver_types.adjust I don't know what the assertion means there, since I never get any exception anyway. The type declaration is: type Udp_message is new Finalization.Controlled with record Data : Stream_Element_Array_Access; Dest : Gnat.Sockets.Sock_addr_type; Date : Calendar.Time; end record; The adjust procedure is: procedure Adjust (This : in out Udp_Message) is begin if This.Data /= null then This.Data := new Stream_Element_Array'(This.Data.all); end if; end Adjust; And the finalize one is: procedure Finalize (This : in out Udp_Message) is begin Free (This.Data); end Finalize; Now, where it gets interesting is that I've double and triple checked that no objects of Udp_Message type are being leaked. Using counters and traces I've certified that every object of that type which is created is eventually finalized. No code mangles with the Data pointer, so there's no outside manipulation which could cause the leak. Is there something flawled in this implementation? I just can't figure why there is a leak. Changing the allocated array to a static array removes the leak. These objects are stored in an Ada.Containers.Doubly_Linked_List, if that could add something. Thanks in advance, A. Mosteo.