Challenge 2: A Deliberate Use-After-Free, Caught by AddressSanitizer — Possible Solution ==================================================================== #include int main() { int *p = malloc(sizeof(int)); *p = 42; free(p); int value = *p; // deliberate use-after-free return value; } Compile with ASan and run: $ gcc -fsanitize=address -g uaf.c -o uaf $ ./uaf Representative AddressSanitizer output: ==12345==ERROR: AddressSanitizer: heap-use-after-free on address 0x... READ of size 4 at 0x... thread T0 #0 0x... in main uaf.c:7 ... freed by thread T0 here: #0 0x... in free #1 0x... in main uaf.c:6 ... previously allocated by thread T0 here: #0 0x... in malloc #1 0x... in main uaf.c:4 WHY THIS WORKS AS AN ANSWER ------------------------------ ASan's report identifies the exact bug type (heap-use-after-free), the exact line of the bad READ (line 7), AND -- unlike a plain crash -- also shows both where the memory was originally allocated (line 4) and where it was freed (line 6), exactly matching the chapter's claim that ASan crashes immediately with a detailed report at the precise moment of the bad access, giving far more diagnostic context than a generic segfault would.