|
Message-ID: <CAJgzZoqYx-G=M55PY_FSs36JS1o0wu4CDoB_gPtvc+zzuECm+A@mail.gmail.com> Date: Fri, 29 Jul 2022 12:39:43 -0700 From: enh <enh@...gle.com> To: musl@...ts.openwall.com Subject: Re: Re: sysconf(_SC_NPROCESSORS_CONF) broken. On Fri, Jul 29, 2022 at 11:53 AM NRK <nrk@...root.org> wrote: > > On Fri, Jul 29, 2022 at 11:42:19AM -0700, enh wrote: > > done: https://android-review.googlesource.com/c/platform/bionic/+/2168844 > > 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: https://android-review.googlesource.com/c/platform/bionic/+/2170542 > > 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 man7.org 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.