[libc-commits] [libc] [llvm] [libc] Release stream buffers with delete[] and stop reallocating them (PR #237127)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Fri Oct 30 01:27:05 PDT 2026
labath wrote:
hm... this may be more complicated than I expected (I somehow though you'd just be adding brackets to `delete`s), so I'm not sure if I'll be able to approve it. That said, I'd say separating this from the `setlinebuf` discussion was the right thing to do, as the allocation strategy is independent from the question from "what does a zero-sized buffer mean".
Now, our allocation strategy, as I understand it (I could be wrong here) is to have all allocations (eventually) call out to malloc, and the idea there is precisely to enable allocator mixing, because we sometimes need to return objects (e.g. strdup) that the user must release (with free), but being implemented in C++, we want to be able to use c++ allocation primitives (new) to allocate/construct objects.
Now, that doesn't mean we should mix allocation functions just for the fun of it, but the current code sort of makes sense: there's no c++ equivalent of realloc, and using realloc potentially does save you from needing to reallocate the buffer.
I guess my question is how real of a problem this is. Did you actually get a sanitizer report on this code? AIUI, that shouldn't be the case as our `operator new(AllocChecker)` calls out to malloc (alloc-checker.h), and our `operator delete` calls out to free (new.cpp).
https://github.com/llvm/llvm-project/pull/237127
More information about the libc-commits
mailing list