mailing list of musl libc
 help / color / mirror / code / Atom feed
From: enh <>
Subject: Re: [musl] Re: sysconf(_SC_NPROCESSORS_CONF) broken.
Date: Fri, 29 Jul 2022 12:39:43 -0700	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <20220729185357.yifwo5wlkyh33dj3@gen2.localdomain>

On Fri, Jul 29, 2022 at 11:53 AM NRK <> wrote:
> On Fri, Jul 29, 2022 at 11:42:19AM -0700, enh wrote:
> > done:
>         if (getline(&line, &allocated_size, fp) != -1) {
>           cpu_count = GetCpuCountFromString(line);
>           free(line);
>         }
> Shouldn't the buffer be `free`-ed regardless or weather getline fails or
> not? The getline(3) manpage suggests so:

yeah, i almost changed that in passing (because i worried that someone
would copy & paste for a loop, where you don't want to free() on every
iteration) but assumed (incorrectly!) that earlier me had checked.

fixed now, thanks:

> > If *lineptr is set to NULL before the call, then getline() will
> > allocate a buffer for storing the line. This buffer should be freed by
> > the user program even if getline() failed.

it looks like it's not entirely theoretical either --- a quick look at
bionic's [OpenBSD] getdelim() implementation shows that it can return
failure on the first call but leaving buf non-null (you'd need the
first allocation to succeed, and need a second allocation that fails;
which -- along with the fact -- is probably why i don't remember ever
seeing this in practice).

i'll send a patch to to mention this in the ERRORS section,
because i didn't see it up top when i looked before getting to the
part of your mail with a ctrl-f'able quote :-)

> - NRK

  reply	other threads:[~2022-07-29 19:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27  6:28 [musl] " Rob Landley
2022-07-27  6:34 ` [musl] " Rob Landley
2022-07-27 17:58   ` Szabolcs Nagy
2022-07-27 21:29     ` Jonathan Rajotte-Julien
2022-07-28 17:27       ` enh
2022-07-29 18:42         ` enh
2022-07-29 18:53           ` NRK
2022-07-29 19:39             ` enh [this message]
2022-07-27 18:05   ` enh
2022-07-27 23:06     ` [musl] dynamic linker is capturing "reserved" library names erroneously Christopher Sean Morrison
2022-07-28  9:18       ` Szabolcs Nagy
2022-07-28 20:39         ` Christopher Sean Morrison
2022-07-29  0:07           ` Rich Felker
2022-07-29  6:19             ` Christopher Sean Morrison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).