about summary refs log tree commit diff
path: root/src/malloc/free.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-11-10 19:32:09 -0500
committerRich Felker <dalias@aerifal.cx>2020-11-11 10:55:13 -0500
commitc1e5d243b7e39b2fbfb17144608ce045575d8e95 (patch)
treef9d8c0743f16e278d30f53a7063412b8e7e4d257 /src/malloc/free.c
parentcbecda0b506c7d49a2f7fe3dc44e0e3dcf663764 (diff)
downloadmusl-c1e5d243b7e39b2fbfb17144608ce045575d8e95.tar.gz
musl-c1e5d243b7e39b2fbfb17144608ce045575d8e95.tar.xz
musl-c1e5d243b7e39b2fbfb17144608ce045575d8e95.zip
drop use of getdelim/stdio in dynamic linker
the only place stdio was used here was for reading the ldso path file,
taking advantage of getdelim to automatically allocate and resize the
buffer. the motivation for use here was that, with shared libraries,
stdio is already available anyway and free to use. this has long been
a nuisance to users because getdelim's use of realloc here triggered a
valgrind bug, but removing it doesn't really fix that; on some archs
even calling the valgrind-interposed malloc at this point will crash.

the actual motivation for this change is moving towards getting rid of
use of application-provided malloc in parts of libc where it would be
called with libc-internal locks held, leading to the possibility of
deadlock if the malloc implementation doesn't follow unwritten rules
about which libc functions are safe for it to call. since getdelim is
required to produce a pointer as if by malloc (i.e. that can be passed
to reallor or free), it necessarily must use the public malloc.

instead of performing a realloc loop as the path file is read, first
query its size with fstat and allocate only once. this produces
slightly different truncation behavior when racing with writes to a
file, but neither behavior is or could be made safe anyway; on a live
system, ldso path files should be replaced by atomic rename only. the
change should also reduce memory waste.
Diffstat (limited to 'src/malloc/free.c')
0 files changed, 0 insertions, 0 deletions