xtc_alloc_audit(3)
---xtc_alloc_audit(3)
debug allocation auditor with per-process leak detection
| XTC_ALLOC_AUDIT(3) | Library Functions Manual | XTC_ALLOC_AUDIT(3) |
NAME
xtc_alloc_audit_enable,
xtc_alloc_audit_stats,
xtc_alloc_audit_proc_leaks —
debug allocation auditor with per-process leak
detection
SYNOPSIS
#include <xtc.h>
#include
<xtc_alloc_audit.h>
int
xtc_alloc_audit_enable(int
on);
void
xtc_alloc_audit_stats(size_t
*out_count, size_t
*out_bytes);
void
xtc_alloc_audit_proc_leaks(xtc_pid_t
pid, size_t
*out_count, size_t
*out_bytes);
DESCRIPTION
The allocation auditor records every live allocation together with
the process
(xtc_self())
that made it, so a test can assert a process freed everything it allocated
before it died.
xtc_alloc_audit_enable()
with a non-zero argument wraps the current allocator hook
(__os_alloc(3)): each allocation calls the previous
(downstream) allocator and is recorded in a hash table keyed by pointer;
each free or realloc removes or re-keys the record. The table's own nodes
are allocated through the downstream hook directly, so the auditor never
audits itself. A zero argument restores the previous hook and frees the
table. It returns XTC_OK, or
XTC_E_NOMEM if the table could not be allocated.
xtc_alloc_audit_stats()
reports the total number of live (unfreed) allocations and their byte sum
across all owners.
xtc_alloc_audit_proc_leaks()
reports the live allocations still attributed to pid
(allocations made off a process are attributed to the none pid). This is the
per-process leak check: call it from the process's
xtc_proc_at_exit(3) hook, or after the process is reaped,
to confirm it leaked nothing.
RETURN VALUES
xtc_alloc_audit_enable() returns
XTC_OK on success or
XTC_E_NOMEM. The query functions write through their
non-NULL output pointers.
PERFORMANCE
The auditor serializes every allocation and free on a global mutex, so it is a debug and test tool, not for production hot paths. It is off by default.
SEE ALSO
AUTHORS
The xtc project.
| May 31, 2026 | Debian |