Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: The Natural Philosopher Newsgroups: comp.os.linux.misc Subject: Re: Joy of this, Joy of that Date: Sat, 23 Nov 2024 11:34:08 +0000 Organization: A little, after lunch Lines: 32 Message-ID: References: <6iKdnTQOKNh6AqD6nZ2dnZfqn_idnZ2d@earthlink.com> <20241120081039.00006d2a@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 23 Nov 2024 12:34:09 +0100 (CET) Injection-Info: dont-email.me; posting-host="d66e216f27af22ed0cfed08003360025"; logging-data="1776478"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QpkURqdaSKI7YTV7ZOngR/y6ZXVR82q0=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:Bt5QHVerncBPMKmMv7TRZfH3NUw= Content-Language: en-GB In-Reply-To: Bytes: 2610 On 23/11/2024 10:16, Richard Kettlewell wrote: > Lawrence D'Oliveiro writes: >> On Sat, 23 Nov 2024 07:09:06 GMT, Charlie Gibbs wrote: >>> So it's the good old-fashioned way - free >>> each allocation one by one and hope you don't forget one. >> >> One thing that helps is that free(3) is idempotent: > > It is not. Freeing the same non-null pointer twice is a bug (and a > common source of vulnerabilities). > >> calling it on a NULL pointer is a harmless no-op, so there is no need >> to check for NULL before calling it. So my standard technique >> (simplifying somewhat) is > > ‘free() and null out all copies of the pointer that can ever reach > free() in the future’ is idempotent, if you can get it right (which is > usually not too hard in a well-organized program). > I had to read that three times to understand what you said there. A comma after the first free() would have helped.:-) Otherwise +100 -- For every complex problem there is an answer that is clear, simple, and wrong. H.L.Mencken