Dynamic Memory Flashcards

1
Q

malloc parameter(s)

A

size of block in bytes

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

malloc return type

A

void pointer to allocated segment

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

calloc parameter(s)

A

number of items, size of item in bytes

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

calloc return type

A

void pointer to allocated segment

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

realloc parameter(s)

A

original pointer, new block size in bytes

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

What happens if memory allocation fails?

A

NULL pointer is returned

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

Dynamic memory functions are stored in what library?

A

stdlib.h

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

Types of memory violations

A

Memory leak, Dangling pointer, Use after free, Double Free, Freeing static memory

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

Not freeing dynamically allocated memory

A

memory leak

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

Using unallocated pointers

A

Dangling pointer

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

Using pointers recently freed

A

Dangling pointer

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

Dereferencing after free

A

Use after free

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

Freeing the same thing twice

A

Double free

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

What happens if you dereference NULL?

A

Segfault

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

What happens if you free NULL?

A

Nothing

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

int arr[100];
free(arr);

A

Freeing static memory

17
Q

free(arr);
arr[0] = 1;

A

Use after free

18
Q

free(arr);
free(arr);

A

double free

19
Q

Fix for double frees and use after frees

A

set what you freed to NULL