Skip to content

Commit 422b6f3

Browse files
committed
check malloc return value in allocator_init
LIST_INIT dereferences the pointer immediately after malloc. A NULL return would crash silently; exit with an error instead. Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
1 parent 0831874 commit 422b6f3

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/allocator/allocator.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ void allocator_init() {
9191
LOG_DEBUG("Allocator_init\n");
9292

9393
device_overallocated = malloc(sizeof(allocated_list));
94+
if (!device_overallocated) {
95+
LOG_ERROR("allocator_init: malloc failed");
96+
exit(EXIT_FAILURE);
97+
}
9498
LIST_INIT(device_overallocated);
95-
device_allocasync=malloc(sizeof(allocated_list));
99+
device_allocasync = malloc(sizeof(allocated_list));
100+
if (!device_allocasync) {
101+
LOG_ERROR("allocator_init: malloc failed");
102+
exit(EXIT_FAILURE);
103+
}
96104
LIST_INIT(device_allocasync);
97105

98106
pthread_mutex_init(&mutex,NULL);

0 commit comments

Comments
 (0)