Skip to content
DEBUG_ALLOCATOR_DEFAULTS

DEBUG_ALLOCATOR_DEFAULTS

Description

All-checks-on DebugAllocatorConfig baseline. Use as the argument to DebugAllocatorInitWith (or the default carried by DebugAllocatorInit) when you want every diagnostic the allocator offers: trace capture, canary overflow detection, freed-history tracking. Page-backed UAF detection is left OFF because it makes freed regions unreclaimable; opt in explicitly via DebugAllocatorInitWith when you want it.

Success

Yields a DebugAllocatorConfig value with capture_traces, detect_overflow, track_freed_history all true, force_page_backing false, trace_depth = 8, canary_bytes = 16.

Failure

Macro cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    /// TAGS: Allocator, Debug, Init
    ///
    #define DebugAllocatorInit() DebugAllocatorInitWith(DEBUG_ALLOCATOR_DEFAULTS)
    
    #endif // MISRA_STD_ALLOCATOR_DEBUG_H
        // When track_freed_history = false, freed Vec stays empty even
        // after many frees -- and allocator is still functional.
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.track_freed_history  = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_debug_page_backed_alloc_free(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.force_page_backing   = true;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_ad1_freed_free_trace_n_zero_when_no_capture(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_ad1_freed_free_trace_n_capped_to_depth(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 2;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_ad1_freed_free_trace_n_clamped_to_max(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 20;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    // lifts the working depth to 16 (clamp) captures up to 16.
    bool test_ad2_trace_depth_respected(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 4; // below MAX_TRACE
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    // and record > 16 frames.
    bool test_ad2_trace_depth_clamped_to_max(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 32; // above MAX_TRACE -> must clamp to 16
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_af_free_trace_depth_clamped(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = true;
        cfg.trace_depth          = 32; // above DEBUG_ALLOCATOR_MAX_TRACE (16)
    // Lean leak-checking DebugAllocator config (no traces / overflow / history).
    static DebugAllocator leak_alloc(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = false;
        cfg.detect_overflow      = false;
Last updated on