This idea of ‘undefined’ behaviour in a programming language is interesting. That safety is about mitigating undefined behaviour. There’s this strict determinism that programs require.
Examples of this in memory management
- Buffer overflow: if data is written on memory that is not ‘assigned’ to it this would have unpredictable consequences for other running programs or the same program.
- If you continue to use a pointer to memory that has been marked as freed (other variables can start using it).
- Double freeing. Freeing the heap twice. You don’t know what’s in there the second time.