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 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-13 18:10:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Free-ing memory: not springing leaks? References: <2TM8b.1013$Nb6.297@newsfep4-winn.server.ntli.net> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 14 Sep 2003 01:10:55 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1063501855 65.110.133.134 (Sat, 13 Sep 2003 18:10:55 PDT) NNTP-Posting-Date: Sat, 13 Sep 2003 18:10:55 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:42462 Date: 2003-09-14T01:10:55+00:00 List-Id: chris writes: > 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. You only free memory on the Ada side that has been allocated on the Ada side. If you have a ptr to memory that has been allocated on the C side, there should also be a function to free that memory. > 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? See above. > I vaguely recall reading somewhere that in general you shouldn't free C > allocated memory from Ada, but perhaps I was mistaken? No, you are correct: don't do that.