From 3aaa7737df6fa466849bf39a02e606f8bce37f66 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Tue, 12 Apr 2022 15:11:16 -0400 Subject: [PATCH] fix: handle NULL from realloc --- runtime/include/priority_queue.h | 2 +- runtime/src/local_runqueue_minheap.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/include/priority_queue.h b/runtime/include/priority_queue.h index 01d3d17..ae92366 100644 --- a/runtime/include/priority_queue.h +++ b/runtime/include/priority_queue.h @@ -292,7 +292,7 @@ priority_queue_initialize(size_t capacity, bool use_lock, priority_queue_get_pri * unclear if the fact that the lock is a member in the struct that might be moved by realloc breaks the guarantees of * the lock. * @param priority_queue to resize - * @returns pointer to PR. This may have been moved by realloc! + * @returns pointer to PR or NULL if realloc fails. This may have been moved by realloc! */ static inline struct priority_queue * priority_queue_grow_nolock(struct priority_queue *priority_queue) diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index b75bbc9..8ba3c29 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -37,7 +37,9 @@ local_runqueue_minheap_add(struct sandbox *sandbox) { int return_code = priority_queue_enqueue_nolock(local_runqueue_minheap, sandbox); if (unlikely(return_code == -ENOSPC)) { - local_runqueue_minheap = priority_queue_grow_nolock(local_runqueue_minheap); + struct priority_queue *temp = priority_queue_grow_nolock(local_runqueue_minheap); + if (unlikely(temp == NULL)) panic("Failed to grow local runqueue\n"); + local_runqueue_minheap = temp; return_code = priority_queue_enqueue_nolock(local_runqueue_minheap, sandbox); if (unlikely(return_code == -ENOSPC)) panic("Thread Runqueue is full!\n"); }