Path: csiph.com!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: Lawrence D'Oliveiro Newsgroups: comp.os.linux.misc Subject: Re: Joy of this, Joy of that Date: Sat, 23 Nov 2024 07:44:35 -0000 (UTC) Organization: A noiseless patient Spider Lines: 15 Message-ID: References: <6iKdnTQOKNh6AqD6nZ2dnZfqn_idnZ2d@earthlink.com> <20241120081039.00006d2a@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 23 Nov 2024 08:44:36 +0100 (CET) Injection-Info: dont-email.me; posting-host="2fd1218dfbbc8c3afa5bbf19b4966652"; logging-data="1710589"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eJC+1z13T8dj6qHPJZovj" User-Agent: Pan/0.161 (Chasiv Yar; ) Cancel-Lock: sha1:Q5JfXvsluuKqjgGegyEfljLVuPQ= Xref: csiph.com comp.os.linux.misc:61256 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: 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 * Initialize all dynamic storage pointers in this scope to NULL * Do the various allocations, processing, etc * Unconditionally free() all dynamic storage pointers in this scope, allocated or not. This keeps the code as simple as I can make it.