Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code
Use-after-free has been designated CWE-416 in the Common Weakness Enumeration database.
This is a software bug in which a program continues to read or write to a memory address after declaring that it is finished with it and returning it to the operating system. This is an example of undefined behaviour in which the compiler makes no guarantees about what will happen when run.
Use-after-free becomes a security problem because if the memory gets assigned to another process, then your program's behaviour can be influenced by another process.