Reading an AddressSanitizer Heap-Use-After-Free — Fault, Freed-By, Allocated-By
A heap-buffer-overflow report has two stacks. A heap-use-after-free report has three, because the question it answers is bigger: not just where the bad access happened, but when the memory stopped being valid and when it started. The fault stack names the use, the freed-by stack names the delete that ended the lifetime, and the allocated-by stack names the allocation that began it — three lines in your code, in an order the source never shows together. This guide frees one heap int, reads through the dangling pointer it leaves behind, and reads the resulting report stack by stack until the three lines tell the whole story, then fixes the lifetime and runs clean.
Written November 19, 2026 · Tested with GCC 13.3.0 · 11 min read
- The program: a pointer that outlives its object
- Building with the sanitizer
- The report
- Reading the report, stack by stack
What this guide is
A heap-use-after-free is an access through a pointer whose object has already been freed: the pointer still holds the address, but the lifetime it pointed into is over. The examples here use GCC 13.3.0 and its AddressSanitizer runtime. The main case is the smallest version of the bug: one int allocated with new, released with delete, and then read through the pointer that still names it. The sanitizer catches that read, and the guide reads the resulting report in full — all three of its stacks, in the order the report prints them, and the location line and shadow bytes that sit between and after them. A second build drops the debug flag so the cost of losing line numbers across three stacks is visible rather than asserted, and a third build drops the sanitizer entirely, where the same read produces a wrong answer and a successful exit. The fix gives the object an owner whose lifetime covers every use, and the fixed program runs to a normal exit under the same sanitizer build.
Nothing in this guide needs a debugger or a core dump. The report is the diagnosis; the work is learning which stack answers which question.
The program: a pointer that outlives its object
#include <iostream>
int main() {
int* value = new int(42);
delete value;
std::cout << *value << "\n";
return 0;
}
The program is eight lines, and three of them are the whole bug. Line 4 allocates an int, stores 42 in it, and keeps its address in value. Line 5 deletes it: the object's lifetime ends there, and the memory goes back to the allocator. Line 6 reads *value and tries to print it. Nothing between lines 5 and 6 changes value — it still holds exactly the address it held on line 4 — and that is precisely the trap. delete ends the object, not the pointer. The pointer is left dangling: a well-formed address naming storage the program no longer owns, holding a value the program has no right to expect. The read on line 6 is where the run ends.
This shape — free in one place, use later somewhere the free is not visible — is why use-after-free survives code review in larger code. Each line looks locally correct. The allocation is real, the delete is real, the read is a normal dereference. What is wrong is purely temporal: the three events happen in the wrong relationship to each other, and no single line shows it. The report below is the document that puts the three lines in one place.
Building with the sanitizer
AddressSanitizer is not a separate program that watches the binary from outside. It is instrumentation the compiler adds to the program itself: memory access instructions are instrumented to detect out-of-bounds and use-after-free bugs, and a runtime library checks each access against a record of which addresses are currently valid. That record is what makes this error class detectable at all — when memory is freed, the runtime poisons its shadow and keeps the region in quarantine instead of handing it straight back out, so a later access through a dangling pointer still finds the poison and stops. The sanitizer is a compile-time choice, made with one flag:
$ g++ -std=c++20 -g -fsanitize=address -o use_after_free use_after_free.cpp
The -fsanitize=address flag does two jobs at once: it compiles the checks into the code and it links the sanitizer runtime into the binary. Leave it off and there is nothing to catch the access — the last-but-one section of this guide runs exactly that build, and the dangling read sails through it with a wrong value and a clean exit. The -g flag is the other half of a useful report. The GCC documentation puts it plainly: when compiling with -fsanitize=address, you should also use -g to produce more meaningful output. Debug information is what lets the runtime print a file name and a line number next to each stack frame instead of a bare offset into the binary. A use-after-free report carries three stacks, so it has three times as much to lose: a later section builds the same program without -g, and every one of the three stacks loses the line that made it worth printing.
One consequence of the instrumentation model is worth stating before the report: the sanitizer knows the address was freed because the runtime replaces the allocation and deallocation functions and records each region's history as it is created and destroyed. An access is checked before it happens. When the check fails, the access never completes — the read value is never produced — and the program stops at that instruction and prints the report. So a sanitizer report is not a description of corruption that already spread. It is a photograph of the first illegal access, taken before it landed.
The report
Run the instrumented program and it stops on the dangling read:
$ ./use_after_free
=================================================================
==28020==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000000010 at pc 0x60136500030d bp 0x7fffb22d3680 sp 0x7fffb22d3670
READ of size 4 at 0x502000000010 thread T0
#0 0x60136500030c in main /home/hatch/workspace/slot5-verify/use_after_free.cpp:6
#1 0x74ba029901c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#2 0x74ba0299028a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#3 0x6013650001a4 in _start (/home/hatch/workspace/slot5-verify/use_after_free+0x11a4) (BuildId: 3f7f4b62a82ca36b48923f1bf2aa46909cf43622)
0x502000000010 is located 0 bytes inside of 4-byte region [0x502000000010,0x502000000014)
freed by thread T0 here:
#0 0x74ba0300d5e8 in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:164
#1 0x6013650002d5 in main /home/hatch/workspace/slot5-verify/use_after_free.cpp:5
#2 0x74ba029901c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#3 0x74ba0299028a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#4 0x6013650001a4 in _start (/home/hatch/workspace/slot5-verify/use_after_free+0x11a4) (BuildId: 3f7f4b62a82ca36b48923f1bf2aa46909cf43622)
previously allocated by thread T0 here:
#0 0x74ba0300c548 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95
#1 0x60136500027e in main /home/hatch/workspace/slot5-verify/use_after_free.cpp:4
#2 0x74ba029901c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#3 0x74ba0299028a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#4 0x6013650001a4 in _start (/home/hatch/workspace/slot5-verify/use_after_free+0x11a4) (BuildId: 3f7f4b62a82ca36b48923f1bf2aa46909cf43622)
SUMMARY: AddressSanitizer: heap-use-after-free /home/hatch/workspace/slot5-verify/use_after_free.cpp:6 in main
Shadow bytes around the buggy address:
0x501ffffffd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x501ffffffe00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x501ffffffe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x501fffffff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x501fffffff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x502000000000: fa fa[fd]fa fa fa fa fa fa fa fa fa fa fa fa fa
0x502000000080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x502000000100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x502000000180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x502000000200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x502000000280: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==28020==ABORTING
The process exits with status 1, and the 42 the program meant to print never appears: execution stopped at the read on line 6, which is the print statement itself — the value it tried to print was never produced. The report is printed to standard error, and it is longer than an overflow report by exactly one stack. The diagnosis lives in six places, taken in order below.
Reading the report, stack by stack
The header: what kind of error, at what address
The first line after the rule names the error class and the address that was touched:
==28020==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000000010 at pc 0x60136500030d bp 0x7fffb22d3680 sp 0x7fffb22d3670
heap-use-after-free is the class: an access to heap memory whose lifetime has ended. It is not a segmentation fault and it is not a guess — the runtime knows the address 0x502000000010 belongs to a region it freed and poisoned, which is a stronger statement than the operating system can make about a dangling pointer. The number before ERROR is the process ID, and the addresses on this line and throughout the report — the program counter, the stack pointers, the heap addresses themselves — change from run to run. They are the least portable part of the report. Everything structural in it — the error class, the access kind, the sizes, the file names and line numbers, the region size — is stable, and those are the parts worth reading closely.
The access line: READ of size 4
READ of size 4 at 0x502000000010 thread T0
The faulting access was a read, 4 bytes wide — the size of one int on this platform, so the access was a single-element load through the dangling pointer, not a bulk copy. The word to hold on to is READ: this program did not write into freed memory, it consumed a value out of it. The two directions fail differently in an unsanitized build. A write into freed memory corrupts whatever the allocator has since placed there. A read from freed memory corrupts nothing; it fabricates an input, and every result the program computes from that input is wrong for a reason no output inspection will reveal — the no-sanitizer run near the end of this guide shows exactly that, printing a number that is not 42 and exiting successfully. When you read a report of your own, this line tells you which failure you are hunting: for a write, what did the stray store damage; for a read, what did the program believe that was never true.
The fault stack: the line that used it
Directly under the access line is the stack of the faulting access:
#0 0x60136500030c in main /home/hatch/workspace/slot5-verify/use_after_free.cpp:6
Frame #0 is the instruction that was checked and stopped: main, in use_after_free.cpp, at line 6. Line 6 of the program as printed above is std::cout << *value << "\n"; — the dangling read. The frames below it are the call chain that reached main — the C runtime's startup code — and for a single-function program they carry no diagnostic weight. In a larger program this stack is the part to read most carefully, because it is the actual path of execution: the top frame is the access itself, and each frame below is a caller, so the stack answers not just where the dangling pointer was dereferenced but which call chain delivered it there. Note what makes this frame readable at all: the file name and the :6. Those come from -g.
On its own, though, the fault stack cannot convict this line. A dereference of value is legal code; it was legal on any line before the delete and would be legal in a program that never deleted at all. What makes line 6 the bug is a fact from a different stack entirely — that the lifetime ended on line 5. That is the freed-by stack's job, and it is why this report needs more stacks than an overflow does.
The location line: 0 bytes inside a 4-byte region
After the fault stack, the report locates the faulting address against the region it belongs to:
0x502000000010 is located 0 bytes inside of 4-byte region [0x502000000010,0x502000000014)
Compare this line with the same line in a heap-buffer-overflow report and the wording carries the diagnosis. An overflow says the address is located some number of bytes after its region — outside it, past the end. This report says the address is located 0 bytes inside its region: the read was aimed at exactly the right place, the first byte of the 4-byte allocation, the very int the program allocated. Nothing about the address is wrong. What is wrong is the time: the region the address sits inside is a region that has been freed. That is the whole difference between the two error classes compressed into one preposition — an overflow is an access in the wrong place, a use-after-free is an access at the wrong time — and it is why no amount of checking the pointer's arithmetic would have found this bug. The pointer arithmetic is perfect.
The freed-by stack: the line that ended it
Next comes the stack that no overflow report has, headed freed by thread T0 here:. Its top frame is the runtime's replacement deallocation function, operator delete(void*, unsigned long), and the frame below it is the line in your code that called it:
#1 0x6013650002d5 in main /home/hatch/workspace/slot5-verify/use_after_free.cpp:5
Line 5 is delete value;. This stack is the middle of the object's life story and the line most likely to be the actual bug. A free is not wrong by itself — every allocation in a correct program is freed exactly once — but the freed-by line is where the report asserts that the lifetime ended, and everything after that moment that touches the address is invalid. When you triage a report of your own, read this line as a question: was this free supposed to be the end? If the object was freed early — by an owner that released it while other code still held pointers to it, by a cleanup path that ran before the last use, by a delete that should have been a move or a copy — the fix belongs here, at the free, not at the use. If the free was correct and the use is the leftover — a cached pointer nobody invalidated, a callback that fired after teardown — the fix belongs at the fault line instead. The report cannot make that judgment; it can only, and does, name both lines so the judgment has somewhere to stand.
The allocated-by stack: the line that began it
The third stack is headed previously allocated by thread T0 here: — the word previously doing quiet work, marking this as history rather than current ownership. Its top frame is the runtime's replacement allocation function, operator new(unsigned long), and the frame below it is the line in your code that called it:
#1 0x60136500027e in main /home/hatch/workspace/slot5-verify/use_after_free.cpp:4
Line 4 is int* value = new int(42);. With this stack the report has reconstructed the object's complete biography in one document: allocated on line 4, freed on line 5, used on line 6. The allocated-by stack rarely names the bug — the allocation is almost never the wrong line — but it earns its place by identifying which object this was. In a program with thousands of allocations, the fault and freed-by stacks tell you a pointer outlived a free; the allocated-by stack tells you which allocation, created where, owned by whom, so you can find every other pointer that shared it. A use-after-free is seldom a single dangling pointer; it is an object that died while references to it were scattered across the program, and the allocation site is the hub those references have in common.
The summary and the shadow bytes
The report closes with a one-line SUMMARY: that repeats the error class and the fault location — the line to paste into a bug report or a search box — and a dump of shadow bytes around the faulting address. The shadow is the runtime's validity map: one shadow byte describes every 8 bytes of program memory, with 00 meaning fully addressable and fa marking a poisoned heap redzone. The row that contains the fault is marked with =>:
=>0x502000000000: fa fa[fd]fa fa fa fa fa fa fa fa fa fa fa fa fa
The bracketed byte is [fd], and fd is the legend's entry for a freed heap region — a different poison from the overflow report's [fa] redzone byte, because the memory is not beside an allocation, it was the allocation. Read the row left to right: two poisoned shadow bytes for the redzone before the region, then the bracketed [fd] covering the freed int itself, then redzone again. The shadow dump rarely changes the diagnosis the three stacks already gave, but it confirms the state: the bytes are poisoned not because they were never valid, but because their validity was revoked. The final line, ==28020==ABORTING, is the runtime ending the process after the report; the program does not continue past a failed check.
The lifetime the three stacks reconstruct
Laid side by side, the three user-code frames are the bug, complete:
| Stack | Line | Event |
|---|---|---|
| Previously allocated by | 4 | int* value = new int(42); — the lifetime begins |
| Freed by | 5 | delete value; — the lifetime ends |
| Fault | 6 | std::cout << *value << "\n"; — a use after the end |
No single line is wrong. The allocation is correct, the delete is correct, the dereference is ordinary. The defect is in the ordering — a use scheduled after the end of the lifetime it depends on — and ordering defects are invisible to line-by-line reading because each line, read alone, tells the truth. That is the practical reason this report prints three stacks where an overflow prints two: an overflow's two stacks (fault and allocation) suffice because its question is spatial, which allocation and where past it; a use-after-free's question is temporal, and answering it takes all three timestamps the runtime recorded. When you open a report of this class, read it as a timeline before you read it as a stack trace: find the three lines, sort them into allocation, free, and use, and then ask the only question that matters — which of the three events is in the wrong place? Move the use earlier, move the free later, or give the object a different owner whose lifetime covers both; every real fix for this class is one of those three, and the fix section below takes the third.
What -g buys: the same report without line numbers
The GCC advice to pair -fsanitize=address with -g costs three times as much here as it does in an overflow report, because there are three stacks to degrade. Build the same program with the sanitizer but without debug information:
$ g++ -std=c++20 -fsanitize=address -o use_after_free_nog use_after_free.cpp
$ ./use_after_free_nog
=================================================================
==28039==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000000010 at pc 0x5db8b14c930d bp 0x7fff3c128420 sp 0x7fff3c128410
READ of size 4 at 0x502000000010 thread T0
#0 0x5db8b14c930c in main (/home/hatch/workspace/slot5-verify/use_after_free_nog+0x130c) (BuildId: ebc4af3b6d8eb2147ba60a09b54cafbad6a717c5)
#1 0x7eb31d6371c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#2 0x7eb31d63728a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#3 0x5db8b14c91a4 in _start (/home/hatch/workspace/slot5-verify/use_after_free_nog+0x11a4) (BuildId: ebc4af3b6d8eb2147ba60a09b54cafbad6a717c5)
0x502000000010 is located 0 bytes inside of 4-byte region [0x502000000010,0x502000000014)
freed by thread T0 here:
#0 0x7eb31dcb45e8 in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:164
#1 0x5db8b14c92d5 in main (/home/hatch/workspace/slot5-verify/use_after_free_nog+0x12d5) (BuildId: ebc4af3b6d8eb2147ba60a09b54cafbad6a717c5)
#2 0x7eb31d6371c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#3 0x7eb31d63728a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#4 0x5db8b14c91a4 in _start (/home/hatch/workspace/slot5-verify/use_after_free_nog+0x11a4) (BuildId: ebc4af3b6d8eb2147ba60a09b54cafbad6a717c5)
previously allocated by thread T0 here:
#0 0x7eb31dcb3548 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95
#1 0x5db8b14c927e in main (/home/hatch/workspace/slot5-verify/use_after_free_nog+0x127e) (BuildId: ebc4af3b6d8eb2147ba60a09b54cafbad6a717c5)
#2 0x7eb31d6371c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#3 0x7eb31d63728a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
#4 0x5db8b14c91a4 in _start (/home/hatch/workspace/slot5-verify/use_after_free_nog+0x11a4) (BuildId: ebc4af3b6d8eb2147ba60a09b54cafbad6a717c5)
The dangling read is still caught — detection does not depend on debug information, because the checks are compiled into the code and the region's history lives in the runtime. The location line is identical: 0 bytes inside the same 4-byte region. What is gone is everything that tied the report to the source. All three user-code frames are now main with an offset into the binary — the fault at use_after_free_nog+0x130c, the free at +0x12d5, the allocation at +0x127e — and the SUMMARY: line repeats the offset form. The report still proves the program read freed memory, and it still shows three events, but it no longer says which lines they were — and in this error class the lines are the diagnosis, because the bug is nothing but the relationship between them. In a one-function program you could recover the lines by disassembling the offsets; in a real program, that recovery work is the difference between a report that is a diagnosis and a report that is a starting point for a debugging session. Build sanitizer binaries with -g. The cost is a larger binary; the benefit is that every frame in your own code, in all three stacks, arrives already resolved to the line that ran.
Without the sanitizer, there is no report
Build the same program with neither flag and run it:
$ g++ -std=c++20 -g -o use_after_free_plain use_after_free.cpp
$ ./use_after_free_plain
1002625088
It prints 1002625088 and exits with status 0. Not 42 — the value the program stored, printed, and expected — but a number with no relationship to anything the source contains, read out of storage the allocator had already taken back and begun reusing for its own bookkeeping. And the run reports success. This is the run that makes the bug expensive in production: not a crash, but a plausible-looking wrong answer delivered by a process that believes it worked. Reading freed memory is undefined behavior, which means this outcome is one possibility among many, not a behavior to rely on: on another run, another allocator, or another allocation pattern, the same line can print 42 and look correct, hand a stale value to a computation that then fails somewhere unrelated, or crash outright. The sanitizer build exists to replace that lottery with a certainty — the first invalid access, stopped, with all three lines attached. A program that passes its tests in a plain build has shown that its outputs looked right; a program that passes the same tests in a sanitizer build has shown that every access it made was inside a lifetime that was still running. Those are different claims, and only the second one covers this bug class.
The fix: extend the lifetime
The bug is that the object's lifetime ended on line 5 while a use remained on line 6. Two of the three general fixes are visible in miniature here — delete later, or do not use after — but the fix that survives contact with real code is the third: give the object an owner whose lifetime is defined by scope, so the free cannot be scheduled before the last use by mistake. The fixed program holds the int in a std::unique_ptr, and there is no delete to misplace:
#include <iostream>
#include <memory>
int main() {
auto value = std::make_unique<int>(42);
std::cout << *value << "\n";
return 0;
}
Compiled the same way as the first program and run under the sanitizer:
$ g++ -std=c++20 -g -fsanitize=address -o fixed fixed.cpp
$ ./fixed
42
It prints 42 — the value that was stored, this time read while the object is alive — and exits with status 0, with no report. A clean sanitizer run is quiet: the absence of a report, with a normal exit and the expected output, is the pass condition. What changed is not the read and not the value; it is who decides when the lifetime ends. In the buggy program the end was a statement, placed by hand, free to be placed wrong. In the fixed program the end is the owner's scope: the unique_ptr destroys the int when main returns, after every use the scope contains, and no line inside the scope can end the lifetime early because no line inside the scope owns that decision. That is the ownership change this error class usually wants. The alternatives each fit a case: if one function genuinely finishes with an object while its caller still needs it, return the object or its owner upward instead of freeing it in place; if several components must observe an object whose lifetime none of them controls, that is the shape std::shared_ptr and std::weak_ptr exist for — shared ownership to extend the lifetime, weak observation that can ask whether the object is still alive instead of assuming it. What none of the fixes do is touch the pointer after the free and hope: setting a dangling pointer to nullptr after delete guards only that one variable, and a use-after-free in real code almost always arrives through a different copy of the pointer — one the null assignment never reached. Fix the lifetime, not the pointer.
Reading any heap-use-after-free report
The same reading order works on reports from larger programs, where the stacks are longer and the freed region is one of thousands:
| Report line | What it tells you | Where to go in the code |
|---|---|---|
heap-use-after-free in the header |
The address belongs to a region that was freed and poisoned | The three stacks; the bug is temporal, not spatial |
READ of size N / WRITE of size N |
Whether the access loaded from or stored into freed memory, and its width | A statement moving an N-byte value at the fault line |
Fault stack frame #0 |
The exact line whose access was stopped | That line's dereference, and every alias of the same pointer |
located K bytes inside an M-byte region |
The access hit the region itself, not space beside it — the address was right | The lifetime, not the pointer arithmetic |
| Freed-by stack | Which deallocation ended the lifetime, and the line that called it | Where the free was scheduled, and whether it was early |
| Allocated-by stack | Which allocation the address belonged to, and the line that created it | The object's owner, and every pointer that shared the allocation |
Shadow row with [fd] bracketed |
The faulting byte is a freed heap region, confirming the state | Confirmation only; the stacks above already carry the diagnosis |
- Start by sorting the three stacks into a timeline — allocated, freed, used — before reading any frame below the top of each; the ordering of the three events is the bug, and the stacks are how the report proves it.
- Decide which event is misplaced: a use that should not exist anymore, a free that fired early, or an owner whose lifetime was too short for both. Every fix in this class moves one of the three.
- Treat the allocated-by line as a directory of suspects: find the other pointers created from that allocation, because the one in the fault stack is rarely the only copy.
- For a
READ, also ask what the program believed on the runs before the sanitizer was switched on — results computed from freed memory were fabricated inputs, and they may have persisted. - Fix the lifetime or the ownership, not the report: nulling the one pointer you can see, delaying the free past the test that caught it, or suppressing the finding all leave the other copies dangling.
- Re-run the same sanitizer build after the fix; the pass condition is a normal exit, the expected output, and no report.
Related guides and tools on this site
- Sanitizer report decoder — paste a sanitizer report and get its parts labeled: the access line, the stacks, and the region line this guide reads by hand.
- Reading an AddressSanitizer Heap-Buffer-Overflow — READ vs WRITE, Traced and Fixed — the companion report with two stacks instead of three: an access in the wrong place, where this guide's is an access at the wrong time.
- C++ Pointers and References — what a pointer like
valueactually holds, and whydeletechanges the object it points to without changing the pointer itself.
Sources
- GCC, Instrumentation Options —
-fsanitize=addressenables AddressSanitizer, a fast memory error detector; memory access instructions are instrumented to detect out-of-bounds and use-after-free bugs, and when compiling with-fsanitize=addressyou should also use-gto produce more meaningful output. - AddressSanitizer wiki, AddressSanitizer — AddressSanitizer is a memory error detector for C and C++ that lists use after free (dangling pointer dereference) among the error classes it finds, and consists of a compiler instrumentation module and a run-time library.
- AddressSanitizer wiki, Use-after-free example — a worked heap-use-after-free report of the same form as this guide's: the access line, the fault stack, the line locating the address inside its region, the freed-by stack, the previously-allocated-by stack, and the shadow bytes.
- AddressSanitizer wiki, AddressSanitizerAlgorithm — how the runtime maps application memory to shadow memory, and how poisoning a shadow byte marks memory the program may not access.
Keep Exploring
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.
Paste sshd -G output and get a hardening verdict on the values your server actually runs.
Paste a server block and get WebSocket, TLS, HSTS, and proxy-header verdicts.
Paste a systemd timer expression and get the specific reason it fails, the normalized form, and the past-date traps the built-in check hides.
The full sysadmin hub \u2014 systemd, cgroups, file tools, and measured Linux comparisons.