From: Arran Cudbard-Bell Date: Wed, 28 Mar 2018 15:52:13 +0000 (+0100) Subject: Check the type of talloced heap elements X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e212b188aec7733e7dd19cd8256d94bf0f3712e6;p=thirdparty%2Ffreeradius-server.git Check the type of talloced heap elements --- diff --git a/src/include/heap.h b/src/include/heap.h index dcaf4ee0f63..52d5ccfa5a1 100644 --- a/src/include/heap.h +++ b/src/include/heap.h @@ -54,7 +54,7 @@ typedef struct fr_heap_t fr_heap_t; * - NULL on error. */ #define fr_heap_talloc_create(_cmp, _talloc_type, _field) \ - _fr_heap_create(_cmp, #_talloc_type, (size_t)offsetof(_talloc_type), _field)) + _fr_heap_create(_cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field)) fr_heap_t *_fr_heap_create(fr_heap_cmp_t cmp, char const *talloc_type, size_t offset); diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index 34d3ca6c890..bc4c4d82da7 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -1336,13 +1336,13 @@ nomem: WORKER_HEAP_INIT(to_decode, worker_message_cmp, fr_channel_data_t, channel.heap_id); WORKER_HEAP_INIT(localized, worker_message_cmp, fr_channel_data_t, channel.heap_id); - worker->runnable = fr_heap_create(worker_runnable_cmp, REQUEST, runnable_id); + worker->runnable = fr_heap_talloc_create(worker_runnable_cmp, REQUEST, runnable_id); if (!worker->runnable) { fr_strerror_printf("Failed creating runnable heap"); goto fail; } - worker->time_order = fr_heap_create(worker_time_order_cmp, REQUEST, time_order_id); + worker->time_order = fr_heap_talloc_create(worker_time_order_cmp, REQUEST, time_order_id); if (!worker->time_order) { fr_strerror_printf("Failed creating time_order heap"); goto fail; diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 7a9408fee31..473c0d756b9 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -1818,7 +1818,7 @@ fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t statu el->kq = -1; /* So destructor can be used before kqueue() provides us with fd */ talloc_set_destructor(el, _event_list_free); - el->times = fr_heap_create(fr_event_timer_cmp, fr_event_timer_t, heap_id); + el->times = fr_heap_talloc_create(fr_event_timer_cmp, fr_event_timer_t, heap_id); if (!el->times) { fr_strerror_printf("Failed allocating event heap"); error: diff --git a/src/lib/util/heap.c b/src/lib/util/heap.c index a722bed8de4..258be23d803 100644 --- a/src/lib/util/heap.c +++ b/src/lib/util/heap.c @@ -109,6 +109,10 @@ int fr_heap_insert(fr_heap_t *hp, void *data) { int32_t child = hp->num_elements; +#ifndef TALLOC_GET_TYPE_ABORT_NOOP + if (hp->type) (void)_talloc_get_type_abort(data, hp->type, __location__); +#endif + /* * Heap is full. Double it's size. */ diff --git a/src/main/pool.c b/src/main/pool.c index 60fc2e80fbc..b6899b83e2d 100644 --- a/src/main/pool.c +++ b/src/main/pool.c @@ -1000,7 +1000,7 @@ fr_pool_t *fr_pool_init(TALLOC_CTX *ctx, * https://code.facebook.com/posts/1499322996995183/solving-the-mystery-of-link-imbalance-a-metastable-failure-state-at-scale/ */ if (!pool->spread) { - pool->heap = fr_heap_create(last_reserved_cmp, fr_pool_connection_t, heap_id); + pool->heap = fr_heap_talloc_create(last_reserved_cmp, fr_pool_connection_t, heap_id); /* * For some types of connections we need to used a different * algorithm, because load balancing benefits are secondary @@ -1020,7 +1020,7 @@ fr_pool_t *fr_pool_init(TALLOC_CTX *ctx, * That way we maximise time between connection use. */ } else { - pool->heap = fr_heap_create(last_released_cmp, fr_pool_connection_t, heap_id); + pool->heap = fr_heap_talloc_create(last_released_cmp, fr_pool_connection_t, heap_id); } if (!pool->heap) { ERROR("%s: Failed creating connection heap", __FUNCTION__); diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index 415aa24f9d3..c51a9dd1808 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -773,7 +773,7 @@ rlm_rcode_t unlang_interpret_synchronous(REQUEST *request, CONF_SECTION *cs, rlm return RLM_MODULE_FAIL; } - MEM(backlog = fr_heap_create(_unlang_request_ptr_cmp, REQUEST, runnable_id)); + MEM(backlog = fr_heap_talloc_create(_unlang_request_ptr_cmp, REQUEST, runnable_id)); old_el = request->el; old_backlog = request->backlog; caller = request->module; diff --git a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c index cd9a5a1cc08..7d6e39c5226 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c @@ -118,7 +118,7 @@ static int mod_instantiate(UNUSED rlm_cache_config_t const *config, void *instan /* * The heap of entries to expire. */ - driver->heap = fr_heap_create(cache_heap_cmp, rlm_cache_rbtree_entry_t, heap_id); + driver->heap = fr_heap_talloc_create(cache_heap_cmp, rlm_cache_rbtree_entry_t, heap_id); if (!driver->heap) { ERROR("Failed to create heap for the cache"); return -1; diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 58e0612e397..9b8c7261900 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -2594,13 +2594,13 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, t->inst = instance; t->el = el; - t->queued = fr_heap_create(queue_cmp, rlm_radius_udp_request_t, heap_id); + t->queued = fr_heap_talloc_create(queue_cmp, rlm_radius_udp_request_t, heap_id); FR_DLIST_INIT(t->blocked); FR_DLIST_INIT(t->full); FR_DLIST_INIT(t->zombie); FR_DLIST_INIT(t->opening); - t->active = fr_heap_create(conn_cmp, rlm_radius_udp_connection_t, heap_id); + t->active = fr_heap_talloc_create(conn_cmp, rlm_radius_udp_connection_t, heap_id); conn_alloc(t->inst, t);