jemalloc/src/safety_check.c
Slobodan Predolac de9ad1450b Drop the jemalloc_internal_includes.h umbrella
Convert the production source files in src/ (69 .c/.cpp) and
test/jemalloc_test.h.in to list the headers they actually use, then
delete the umbrella.  Three consolidated headers (peak_event.h,
prof_sys.h, sz.h) also gain explicit transitive includes.

Every translation unit now declares what it uses.  A missing include
now fails at the failing file rather than silently working because
something upstream pulled in the world.
2026-06-04 11:32:53 -04:00

48 lines
1.4 KiB
C

#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/malloc_io.h"
#include "jemalloc/internal/safety_check.h"
void
safety_check_fail_sized_dealloc(bool current_dealloc, const void *ptr,
size_t true_size, size_t input_size) {
char *src = current_dealloc
? "the current pointer being freed"
: "in thread cache, possibly from previous deallocations";
char *suggest_debug_build = config_debug ? "" : " --enable-debug or";
safety_check_fail(
"<jemalloc>: size mismatch detected (true size %zu "
"vs input size %zu), likely caused by application sized "
"deallocation bugs (source address: %p, %s). Suggest building with"
"%s address sanitizer for debugging. Abort.\n",
true_size, input_size, ptr, src, suggest_debug_build);
}
/*
* In addition to malloc_write, also embed hint msg in the abort function name
* because there are cases only logging crash stack traces.
*/
static void
safety_check_detected_heap_corruption___run_address_sanitizer_build_to_debug(
const char *buf) {
if (test_hooks_safety_check_abort == NULL) {
malloc_write(buf);
abort();
} else {
test_hooks_safety_check_abort(buf);
}
}
void
safety_check_fail(const char *format, ...) {
char buf[MALLOC_PRINTF_BUFSIZE];
va_list ap;
va_start(ap, format);
malloc_vsnprintf(buf, MALLOC_PRINTF_BUFSIZE, format, ap);
va_end(ap);
safety_check_detected_heap_corruption___run_address_sanitizer_build_to_debug(
buf);
}