🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.linux.misc
Article #1991

Re: Substantive Comments Please: GCC vs. LLMV

#1991
From: Richard Kettlewell
Date: Tue, 03 Nov 2026 18:44
54 lines
3617 bytes
Chris Ahlstrom <OFeem1987@teleworm.us> writes:
> rbowman wrote this screed in ALL-CAPS (fixed):
>> On Mon, 2 Nov 2026 14:18:27 -0500, Chris Ahlstrom wrote:
>>> It found a few issues in a couple of my projects, a few issues
>>> important.
>>> There is one that I don't get
>>> 
>>>    subprojects/libcfg66/src/util/filefunctions.cpp:1138:33: warning:
>>>    Memory allocated by 'new[]' should be deallocated by 'delete[]',
>>>    not 'getline()' [unix.MismatchedDeallocator]
>>> 
>>>  1138 |   ssize_t count { getline(&destination, &maxim, input) };
>>>       |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> 
>>> I guess I need to use malloc() instead.
>>
>> Did you allocate destination with new? getline will malloc a buffer
>> if you pass in NULL.
>
> Yes, and I know that from the man page.
>
> The point is scan-build complaining about something getline() will
> not do in the given use case.
>
> A limitation of static analysis, perhaps.

There’s not enough context to give a completely definitive answer, but:

1) Heap memory can be managed with new/delete, or with
   malloc/realloc/free, but not both. The consequences of playing
   mix-and-match vary between platform, so you might get away with it in
   some cases, by luck, but static analysis tools will consider it a
   bug, if they’re smart enough to notice.

2) In getline(), if *lineptr!=NULL then it will call realloc() on it if
   the line from stream needs more than *n bytes (using argument names
   from [1]). So passing a pointer allocated with new to it is a bug,
   for the reasons given in (1) above.

3) The diagnostic referring to deallocation reather than realloc is
   probably a (trivial) bug in the tool - for example it may model
   realloc as malloc+free, which isn’t unreasonable as such, but leads
   to an opaque diagnostic.

The only case where it would not be a bug is if the line read by
getline() can never possibly exceed the initial allocation. Whether this
is true in your use case I don’t know, but your static analysis tool
either couldn’t prove that it was or more likely, isn’t equipped to do
so.

[1] https://man7.org/linux/man-pages/man3/getline.3.html

-- 
https://www.greenend.org.uk/rjk/
Technical Details
Message-ID: <wwvtslxsqkd.fsf@LkoBDZeT.terraraq.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.uk!not-for-mail
References: <18e37e973e22a7a6$1$3179723$802601b3@news.usenetexpress.com> <11c7kmg$22g7e$1@dont-email.me> <11c80ic$26et9$4@dont-email.me> <11cafc8$31pdt$1@dont-email.me> <11canpv$35aju$1@dont-email.me> <nks9f4F2rmsU5@mid.individual.net> <11ccn72$3p6mj$2@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.uk!not-for-mail
From: Richard Kettlewell <invalid@invalid.invalid>
Newsgroups: comp.os.linux.misc
Subject: Re: Substantive Comments Please: GCC vs. LLMV
Date: Tue, 03 Nov 2026 18:44:18 +0000
Organization: terraraq NNTP server
Message-ID: <wwvtslxsqkd.fsf@LkoBDZeT.terraraq.uk>
References: <18e37e973e22a7a6$1$3179723$802601b3@news.usenetexpress.com>
	<11c7kmg$22g7e$1@dont-email.me> <11c80ic$26et9$4@dont-email.me>
	<11cafc8$31pdt$1@dont-email.me> <11canpv$35aju$1@dont-email.me>
	<nks9f4F2rmsU5@mid.individual.net> <11ccn72$3p6mj$2@dont-email.me>
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.uk:172.17.207.6";
	logging-data="25730"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:rHiFLkhbDM0I9Z7mp15x0CUnUPo=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
     F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
     +r0NzP?vnz:e/knOY)PI-
X-Boydie: NO