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-18 13:30:16 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Free-ing memory: not springing leaks? References: <2TM8b.1013$Nb6.297@newsfep4-winn.server.ntli.net> <9JY8b.1963$WI3.25442@newsfep4-glfd.server.ntli.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <1noab.7755$BT1.356918@news20.bellglobal.com> Date: Thu, 18 Sep 2003 16:15:08 -0400 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1063916093 198.96.223.163 (Thu, 18 Sep 2003 16:14:53 EDT) NNTP-Posting-Date: Thu, 18 Sep 2003 16:14:53 EDT Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:42666 Date: 2003-09-18T16:15:08-04:00 List-Id: chris wrote: > Matthew Heaney wrote: > > > chris.danx wrote: > >>> For example, the library loader for linux error mechanism is to return >>> an error msg describing the problem. Once you have it appears to be >>> your problem what you do with it. There is no call present in the >>> library to return the memory. >> >> This is an Ada binding? Who wrote it? > > No it is a C library for loading libraries at runtime. Its' error > handling returns errors as strings (customised to the library & call > made) - though it'd be easier if it was ints, the errors can be for a > variety of reasons but you need to parse them to handle them effectively! > > const char *dlerror(void); There is no mention in the man pages that it is "allocated", or that you should free it. Just like strerror(), you are given a pointer to a human readable message, which you can use, but not modify. Unless you are given clear instructions to the contrary, do _not_ free it. If you want to decide the issue with 100% certainty, get the Linux sources and examine how they use it. But I would say from my own extensive UNIX/Linux C experience, that you do not need to worry about freeing this pointer. > I wrote a binding to it, but did not know at the time free-ing C memory > from Ada (with Interfaces.C.Strings.Free) was a no-no. Well, as someone else pointed out, GNAT does use malloc() and free() under the hood. In the interest of greater portability however, I would code such that C allocated storage was released in C code, and vice versa. > The binding > takes the error message, converts it to an Ada string, Good.. > free's the memory > of the C string (with Interfaces.C.Strings.Free) ..bad, in any language. ;-) It is not meant to be user freed (just like strerror()). > I will change this soon to use the native C compilers/libs "Free" Don't free it. It is not meant to be freed. > And if you don't, then it's hit and miss? ... it figures. I wonder how > C programmers deal with this :( A lot of it is just a language lawyer's scrutiny of the man pages! However, with Linux/FreeBSD etc., the final truth is contained in the source (Use the "source" Luke!) > Thanks for your help, it's much appreciated. > > Chris Ada bindings can be so much fun. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg