Use after free (UAF) is a type of bug that can be exploited in programming languages that are not memory-safe. In C++, a developer is responsible for allocating (and deallocating) memory on either the stack or the heap. While memory on the stack is statically allocated, memory on the heap can be dynamically allocated and deallocated.