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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cc05aeb5e0d8b475,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-13 15:29:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!area.cu.mi.it!newsfeeder.edisontel.com!skynet.be!skynet.be!newsgate.cistron.nl!news.cambrium.nl!news.cambrium.nl!news.cambrium.nl!news2.euro.net!newspeer1-gui.server.ntli.net!ntli.net!newsfep4-winn.server.ntli.net.POSTED!53ab2750!not-for-mail From: chris User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5b) Gecko/20030903 Thunderbird/0.2 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Free-ing memory: not springing leaks? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <2TM8b.1013$Nb6.297@newsfep4-winn.server.ntli.net> Date: Sat, 13 Sep 2003 23:33:32 +0200 NNTP-Posting-Host: 81.98.236.164 X-Complaints-To: abuse@ntlworld.com X-Trace: newsfep4-winn.server.ntli.net 1063492158 81.98.236.164 (Sat, 13 Sep 2003 23:29:18 BST) NNTP-Posting-Date: Sat, 13 Sep 2003 23:29:18 BST Organization: ntl Cablemodem News Service Xref: archiver1.google.com comp.lang.ada:42461 Date: 2003-09-13T23:33:32+02:00 List-Id: Hi, When you bind to c code, how do you deal with memory? I bound to a function in Lua, function Lua_Version return ICS.Chars_Ptr; pragma Import (C, Lua_Version); but upon free-ing the memory it gave a storage_error. function Version return String is X : ICS.Chars_Ptr := Lua_Version; begin declare Y : String := ICS.Value (X); begin ICS.Free (X); return Y; end; end Version; To be clear, my understanding of this code is it get's a ptr to a null terminated string from Lua_Version, get's that value as a string, frees the null terminated string and returns the ada string. Clearly, something is wrong with my understanding of how this works; if you free the memory it gives a storage error. How then, do you deal with memory leaks? If you bind to a c function and it allocates a chunk of memory and returns it, how do get rid of it and not cause leaks? Remove Free and no error occurs. Perhaps this is a special case? I vaguely recall reading somewhere that in general you shouldn't free C allocated memory from Ada, but perhaps I was mistaken? Can anyone please help with some advice or clarification? I have only ever preallocated memory, passed it to a C function and released it afterwards (e.g. to pass strings into C functions) not had memory given by a c function and tried to release it. Thanks, Chris