mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
preserve errno across free
as an outcome of Austin Group issue #385, future versions of the standard will require free not to alter the value of errno. save and restore it individually around the calls to madvise and munmap so that the cost is not imposed on calls to free that do not result in any syscall.
This commit is contained in:
parent
9afed99c22
commit
2010df0d64
1 changed files with 10 additions and 2 deletions
|
@ -119,7 +119,11 @@ void free(void *p)
|
|||
if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
|
||||
unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
|
||||
size_t len = (end-base) & -PGSZ;
|
||||
if (len) madvise(base, len, MADV_FREE);
|
||||
if (len) {
|
||||
int e = errno;
|
||||
madvise(base, len, MADV_FREE);
|
||||
errno = e;
|
||||
}
|
||||
}
|
||||
|
||||
// atomic free without locking if this is neither first or last slot
|
||||
|
@ -139,5 +143,9 @@ void free(void *p)
|
|||
wrlock();
|
||||
struct mapinfo mi = nontrivial_free(g, idx);
|
||||
unlock();
|
||||
if (mi.len) munmap(mi.base, mi.len);
|
||||
if (mi.len) {
|
||||
int e = errno;
|
||||
munmap(mi.base, mi.len);
|
||||
errno = e;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue