Dynamic Memory Pitfalls Flashcards
(4 cards)
1
Q
What is memory leaks?
A
- Forget to free() memory
- overwrote the last pointer, losing access to the memory
2
Q
What is buffer overflow?
A
When you write more memory than you can hold
- Ex. ask for 10 bytes of memory but write 11
3
Q
Why should you always check for null when you use malloc?
A
Because malloc is allowed to return NULL (out of memory)
4
Q
Passing a pointer to the middle of allocated region to free()
A
Free needs to know exactly what it needs to free, if you try to free the middle of what you want to free, it will cause an error