tests/malloc: fix of dereferencing a NULL pointer
If the memory is exhausted during the allocation of the new `head` structure, subsequent accesses to `head` will result in dereferencing of a NULL pointer.
This commit is contained in:
parent
c391ed4109
commit
136849661a
@ -38,8 +38,10 @@ void fill_memory(struct node *head)
|
||||
printf("Allocated %d Bytes at 0x%p, total %d\n", CHUNK_SIZE, head->ptr, total += CHUNK_SIZE);
|
||||
memset(head->ptr, '@', CHUNK_SIZE);
|
||||
head = head->next = malloc(sizeof(struct node));
|
||||
head->ptr = 0;
|
||||
head->next = 0;
|
||||
if (head) {
|
||||
head->ptr = 0;
|
||||
head->next = 0;
|
||||
}
|
||||
total += sizeof(struct node);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user