Path: ...!feeds.phibee-telecom.net!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!news.gegeweb.eu!gegeweb.org!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail From: Richard Kettlewell Newsgroups: comp.lang.c Subject: Re: avoiding strdup() Date: Mon, 11 Mar 2024 19:11:33 +0000 Organization: terraraq NNTP server Message-ID: References: <87y1ayj6hs.fsf_-_@bsb.me.uk> <87r0gizzuo.fsf@nosuchdomain.example.com> <20240310101101.00001fd4@yahoo.com> <20240310100715.866@kylheku.com> <20240311104527.444@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6"; logging-data="19315"; mail-complaints-to="usenet@innmantic.terraraq.uk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cancel-Lock: sha1:StlCtbDup8xr2MCgIhJ6/Zj/wTQ= X-Face: h[Hh-7npe<v9!1Z&W?r\c.!4DXH5PWpga"ha +r0NzP?vnz:e/knOY)PI- X-Boydie: NO Bytes: 2726 Lines: 24 Kaz Kylheku <433-929-6894@kylheku.com> writes: > Scott Lurndal wrote: >> Malcolm McLean writes: >>>On 10/03/2024 18:47, Scott Lurndal wrote: >>>> Kaz Kylheku <433-929-6894@kylheku.com> writes: >>>>> Not take up space in every application for a common library routine. >>>> >>>> It's a form of lazy programming. I've seen a lot of open source >>>> code that uses strdup without checking for failure and frequently >>>> "forgetting" to free the result. >>> >>>And it is probably more likely that machine with many gigabytes of RAM >> >> Actually, your assumptions that: >> 1) strdup is the only allocation function used by an application >> 2) all strings are "short" > > Even if a string is long enough to need its own mmap request, > that will still return valid memory that later fails to commit. Since strdup necessarily writes to almost all the memory it allocates, you’d expect the failure to be immediate. -- https://www.greenend.org.uk/rjk/