[GAP] unbounded strings package

Ted Baker baker at cs.fsu.edu
Thu Sep 22 15:15:03 CEST 2005


In class, I used the package Ada.Strings.Unbounded as an example of
how to use controlled types.  I ran into a surprise.  Am I blind, or
does this leak storage?

S : Unbounded_String;
...
S := S & 'c';

The Adjust procedure looks like this:

procedure Adjust (Object : in out Unbounded_String) is
begin
   --  Copy string, except we do not copy the statically allocated null
   --  string, since it can never be deallocated.
   if Object.Reference /= Null_String'Access then
      Object.Reference := new String'(Object.Reference.all);
   end if;
end Adjust;

I was expecting that it would free the old reference before
assigning the new one.

--Ted


More information about the GAP mailing list