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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why should you always check for null when you use malloc?

A

Because malloc is allowed to return NULL (out of memory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly