From: Arran Cudbard-Bell Date: Mon, 8 Mar 2021 16:05:27 +0000 (+0000) Subject: Use a macro for checking heap insertion X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c35ad43ba08aec002f2ed30d2d2fa2754849afe0;p=thirdparty%2Ffreeradius-server.git Use a macro for checking heap insertion Not the first time the wrong assert has been used for this --- diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index e1ecdef74ca..acb50b3147b 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -495,11 +495,11 @@ static void worker_send_reply(fr_worker_t *worker, request_t *request, size_t si * and insert it back into a slab allocator. */ finished: - if (request->time_order_id >= 0) (void) fr_heap_extract(worker->time_order, request); - if (request->runnable_id >= 0) (void) fr_heap_extract(worker->runnable, request); + if (fr_heap_entry_inserted(request->time_order_id)) (void) fr_heap_extract(worker->time_order, request); + if (fr_heap_entry_inserted(request->runnable_id)) (void) fr_heap_extract(worker->runnable, request); - fr_assert(request->time_order_id < 0); - fr_assert(request->runnable_id < 0); + fr_assert(!fr_heap_entry_inserted(request->time_order_id)); + fr_assert(!fr_heap_entry_inserted(request->runnable_id)); #ifndef NDEBUG request->async->el = NULL; @@ -685,7 +685,7 @@ static void worker_request_time_tracking_start(fr_worker_t *worker, request_t *r * strict time priority. Once they are in the list, they * are only removed when the request is done / free'd. */ - fr_assert(request->time_order_id < 0); + fr_assert(!fr_heap_entry_inserted(request->time_order_id)); (void) fr_heap_insert(worker->time_order, request); /* diff --git a/src/lib/server/request.c b/src/lib/server/request.c index c57d9f18bc6..2faebf8cc2e 100644 --- a/src/lib/server/request.c +++ b/src/lib/server/request.c @@ -290,8 +290,8 @@ static inline CC_HINT(always_inline) int request_init(char const *file, int line */ static int _request_free(request_t *request) { - fr_assert(request->time_order_id <= 0); - fr_assert(request->runnable_id <= 0); + fr_assert(!fr_heap_entry_inserted(request->time_order_id)); + fr_assert(!fr_heap_entry_inserted(request->runnable_id)); /* * Reinsert into the free list if it's not already diff --git a/src/lib/util/heap.h b/src/lib/util/heap.h index 480ad2503bc..1bd3d713f67 100644 --- a/src/lib/util/heap.h +++ b/src/lib/util/heap.h @@ -82,6 +82,14 @@ typedef struct fr_heap_s fr_heap_t; fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *talloc_type, size_t offset); +/** Check if an entry is inserted into a heap + * + */ +static inline bool fr_heap_entry_inserted(int32_t heap_id) +{ + return (heap_id >= 0); +} + int fr_heap_insert(fr_heap_t *hp, void *data) CC_HINT(nonnull); int fr_heap_extract(fr_heap_t *hp, void *data) CC_HINT(nonnull(1)); void *fr_heap_pop(fr_heap_t *hp) CC_HINT(nonnull);