From 9f7cf1d279424a217ca573f854b6da5cb464df32 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Fri, 13 Sep 2019 11:21:46 -0400 Subject: [PATCH] Fix: fd-cache: Assertion failure if cache not allocated Issue ===== When initializing a `flt.lttng-utils.debug-info` message iterator, errors may occur before the initialization of the iterator's `bt_fd_cache`. If that occurs, the iterator is destroyed using the `debug_info_msg_iter_destroy()` function which calls the `bt_fd_cache_fini()` function. Leading to the `fdc->cache` being NULL and thus triggering an assertion failure. Solution ======== Change the `BT_ASSERT()` to an early return. Drawbacks ========= None. Signed-off-by: Francis Deslauriers Change-Id: Ib6abd595f1c4365836cacd0357c7323f0b4c6385 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2044 Tested-by: jenkins Reviewed-by: Simon Marchi --- src/fd-cache/fd-cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fd-cache/fd-cache.c b/src/fd-cache/fd-cache.c index 9a742a45..c2907a04 100644 --- a/src/fd-cache/fd-cache.c +++ b/src/fd-cache/fd-cache.c @@ -120,13 +120,17 @@ int bt_fd_cache_init(struct bt_fd_cache *fdc, int log_level) BT_HIDDEN void bt_fd_cache_fini(struct bt_fd_cache *fdc) { - BT_ASSERT(fdc->cache); + if (!fdc->cache) { + goto end; + } + /* * All handle should have been removed for the hashtable at this point. */ BT_ASSERT(g_hash_table_size(fdc->cache) == 0); g_hash_table_destroy(fdc->cache); +end: return; } -- 2.34.1