diff --git a/src/jemalloc.c b/src/jemalloc.c index a3694761..fd306a41 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -1035,6 +1035,7 @@ void free_default(void *ptr) { UTRACE(ptr, 0, 0); if (likely(ptr != NULL)) { + int saved_errno = get_errno(); /* * We avoid setting up tsd fully (e.g. tcache, arena binding) * based on only free() calls -- other activities trigger the @@ -1061,6 +1062,7 @@ free_default(void *ptr) { } check_entry_exit_locking(tsd_tsdn(tsd)); + set_errno(saved_errno); } } @@ -1896,6 +1898,7 @@ inallocx(tsdn_t *tsdn, size_t size, int flags) { JEMALLOC_NOINLINE void sdallocx_default(void *ptr, size_t size, int flags) { + int saved_errno = get_errno(); assert(ptr != NULL); assert(malloc_initialized() || malloc_is_initializer()); @@ -1918,6 +1921,7 @@ sdallocx_default(void *ptr, size_t size, int flags) { isfree(tsd, ptr, usize, tcache, true); } check_entry_exit_locking(tsd_tsdn(tsd)); + set_errno(saved_errno); } JEMALLOC_EXPORT void JEMALLOC_NOTHROW diff --git a/src/pages.c b/src/pages.c index 5c12ae42..bec1cfdc 100644 --- a/src/pages.c +++ b/src/pages.c @@ -662,11 +662,6 @@ pages_purge_process_madvise_impl( return true; } - /* - * TODO: remove this save/restore of errno after supporting errno - * preservation for free() call properly. - */ - int saved_errno = get_errno(); size_t purged_bytes = (size_t)syscall(JE_SYS_PROCESS_MADVISE_NR, PIDFD_SELF, (struct iovec *)vec, vec_len, MADV_DONTNEED, 0); if (purged_bytes == (size_t)-1) { @@ -676,7 +671,6 @@ pages_purge_process_madvise_impl( atomic_store_b( &process_madvise_gate, false, ATOMIC_RELAXED); } - set_errno(saved_errno); } return purged_bytes != total_bytes;