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,345a8b767542016e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-19 15:43:35 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!nycmny1-snh1.gtei.net!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3C97CD1F.A675D84F@raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: memory leakages with Ada? References: <3c90af1e@news.starhub.net.sg> <3c91bfa3.1987537@news.demon.co.uk> <3C921A81.9060708@mail.com> <3C962624.5080008@home.com> <3c97027d.1284426@news.demon.co.uk> <3C97713C.1040805@home.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 19 Mar 2002 17:43:27 -0600 NNTP-Posting-Host: 192.27.48.39 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1016581415 192.27.48.39 (Tue, 19 Mar 2002 17:43:35 CST) NNTP-Posting-Date: Tue, 19 Mar 2002 17:43:35 CST Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:21471 Date: 2002-03-19T17:43:27-06:00 List-Id: "Frank J. Lhota" wrote: > > Yes, it is true that instantiations of Ada.Unchecked_Deallocation are > required to do nothing if called with a null access value. This is also true > of the C/C++ equivalents, i.e. the C call "free(NULL)" should also do > nothing, according to the standard. > > I'm not sure why this is bad. A little history. I have an old copy of K&R (Chapter 8, p 177) and the implementation in that book for alloc/free will blow up if you provide a NULL pointer to free. It is coded something like the following... free(ap) char *ap; { register HEADER *p, *q; p = (HEADER *)ap-1; [at this point, p generally has an invalid address if ap is NULL] There MAY still be some broken implementations using this code sequence .... :-) That is not to say that a general method of... free(p) p = NULL; (or the Ada equivalent) is one way of making your code far more robust than keeping the dangling pointers around. I use a method like that to... o allow for a check for NULL pointers to determine if the data is valid o get an immediate exception when I forget to check & dereference a NULL pointer (many machines) o it prevents a subsequent free to that pointer - a known bad operation on several systems That it has the additional benefit of being a "no operation" to free is a side effect I would just as soon not exercise. --Mark