]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use a macro for checking heap insertion
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 8 Mar 2021 16:05:27 +0000 (16:05 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 8 Mar 2021 16:06:05 +0000 (16:06 +0000)
Not the first time the wrong assert has been used for this

src/lib/io/worker.c
src/lib/server/request.c
src/lib/util/heap.h

index e1ecdef74ca558fede59f03f80bb1c13fcb6dae8..acb50b3147bd3a0a96dd18c9c6550e30ac420743 100644 (file)
@@ -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);
 
        /*
index c57d9f18bc6b242f807319c7ef0878783668e7e2..2faebf8cc2ebbf2b151fc3214b6a438e4d2c24ef 100644 (file)
@@ -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
index 480ad2503bcd1d03647edfa8c7922c998e9a3818..1bd3d713f673b036c41d269bf9ec9e7ca69f0307 100644 (file)
@@ -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);