From 2a8281fdfd93eeb3a371e74b1df7a721a986cbac Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 21 Jan 2020 01:08:31 -0500 Subject: [PATCH] thread: free message event after executing the callback successfully We should check the thread's state at the end of message callback, or we may leak the message memory in case the thread was set to exit state. Change-Id: Ifb67c3b5c39440c411eca1d045c11e8aa6c514cc Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/482206 Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Community-CI: SPDK CI Jenkins Tested-by: SPDK CI Jenkins --- lib/thread/thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 15f411666..136e92bcb 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -432,10 +432,6 @@ _spdk_msg_queue_run_batch(struct spdk_thread *thread, uint32_t max_msgs) assert(msg != NULL); msg->fn(msg->arg); - if (thread->exit) { - break; - } - if (thread->msg_cache_count < SPDK_MSG_MEMPOOL_CACHE_SIZE) { /* Insert the messages at the head. We want to re-use the hot * ones. */ @@ -444,6 +440,10 @@ _spdk_msg_queue_run_batch(struct spdk_thread *thread, uint32_t max_msgs) } else { spdk_mempool_put(g_spdk_msg_mempool, msg); } + + if (thread->exit) { + break; + } } return count;