mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-25 06:13:13 +00:00
Preserve errno across free, free_sized, and free_aligned_sized
This commit is contained in:
@@ -1035,6 +1035,7 @@ void
|
|||||||
free_default(void *ptr) {
|
free_default(void *ptr) {
|
||||||
UTRACE(ptr, 0, 0);
|
UTRACE(ptr, 0, 0);
|
||||||
if (likely(ptr != NULL)) {
|
if (likely(ptr != NULL)) {
|
||||||
|
int saved_errno = get_errno();
|
||||||
/*
|
/*
|
||||||
* We avoid setting up tsd fully (e.g. tcache, arena binding)
|
* We avoid setting up tsd fully (e.g. tcache, arena binding)
|
||||||
* based on only free() calls -- other activities trigger the
|
* based on only free() calls -- other activities trigger the
|
||||||
@@ -1061,6 +1062,7 @@ free_default(void *ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
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
|
JEMALLOC_NOINLINE void
|
||||||
sdallocx_default(void *ptr, size_t size, int flags) {
|
sdallocx_default(void *ptr, size_t size, int flags) {
|
||||||
|
int saved_errno = get_errno();
|
||||||
assert(ptr != NULL);
|
assert(ptr != NULL);
|
||||||
assert(malloc_initialized() || malloc_is_initializer());
|
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);
|
isfree(tsd, ptr, usize, tcache, true);
|
||||||
}
|
}
|
||||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
check_entry_exit_locking(tsd_tsdn(tsd));
|
||||||
|
set_errno(saved_errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JEMALLOC_EXPORT void JEMALLOC_NOTHROW
|
JEMALLOC_EXPORT void JEMALLOC_NOTHROW
|
||||||
|
|||||||
@@ -662,11 +662,6 @@ pages_purge_process_madvise_impl(
|
|||||||
return true;
|
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,
|
size_t purged_bytes = (size_t)syscall(JE_SYS_PROCESS_MADVISE_NR,
|
||||||
PIDFD_SELF, (struct iovec *)vec, vec_len, MADV_DONTNEED, 0);
|
PIDFD_SELF, (struct iovec *)vec, vec_len, MADV_DONTNEED, 0);
|
||||||
if (purged_bytes == (size_t)-1) {
|
if (purged_bytes == (size_t)-1) {
|
||||||
@@ -676,7 +671,6 @@ pages_purge_process_madvise_impl(
|
|||||||
atomic_store_b(
|
atomic_store_b(
|
||||||
&process_madvise_gate, false, ATOMIC_RELAXED);
|
&process_madvise_gate, false, ATOMIC_RELAXED);
|
||||||
}
|
}
|
||||||
set_errno(saved_errno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return purged_bytes != total_bytes;
|
return purged_bytes != total_bytes;
|
||||||
|
|||||||
Reference in New Issue
Block a user