From 0368b49ea72cd5f8f139bf2eca5ae01ea070a0ff Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Thu, 22 Dec 2022 12:43:03 +0200 Subject: [PATCH] logging: fix error handling in link_filters_init If k_malloc() of filters fails in log_mgmt.c:link_filters_init(), return an error and do not rely on the __ASSERT(0). If __ASSERT_ON==0 in the build, assert will not trigger and code will proceed to execute memset(NULL, 0, sizeof(uint32_t) * total_cnt); Avoid this by returning -ENOMEM on error. Signed-off-by: Kai Vehmanen --- subsys/logging/log_mgmt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/logging/log_mgmt.c b/subsys/logging/log_mgmt.c index 9f27983bced..e7609810bff 100644 --- a/subsys/logging/log_mgmt.c +++ b/subsys/logging/log_mgmt.c @@ -137,6 +137,7 @@ static int link_filters_init(const struct log_link *link) if (link->ctrl_blk->filters == NULL) { LOG_ERR("Failed to allocate buffer for runtime filtering."); __ASSERT(0, "Failed to allocate buffer."); + return -ENOMEM; } memset(link->ctrl_blk->filters, 0, sizeof(uint32_t) * total_cnt);