From fa22f535edca8a747e70c5e9c534028f118b72fe Mon Sep 17 00:00:00 2001 From: eeff Date: Thu, 27 Jan 2022 15:42:01 +0800 Subject: [PATCH] Fix neu_manager loop memory leak when sub/unsub node --- src/core/neu_manager.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/neu_manager.c b/src/core/neu_manager.c index 934b5865..d4e21f63 100644 --- a/src/core/neu_manager.c +++ b/src/core/neu_manager.c @@ -1415,11 +1415,15 @@ static void manager_loop(void *arg) cmd_ptr->grp_config); msg_pipe = src_reg_entity->adapter_pipe; nng_mtx_unlock(manager->adapters_mtx); - msg_size = msg_inplace_data_get_size(sizeof(subscribe_node_cmd_t)); - rv = nng_msg_alloc(&out_msg, msg_size); need_forward = sub_grp_config_with_pipe( cmd_ptr->grp_config, sub_reg_entity->adapter_pipe); - if (rv == 0 && need_forward == 1) { + if (0 == need_forward) { + break; + } + + msg_size = msg_inplace_data_get_size(sizeof(subscribe_node_cmd_t)); + rv = nng_msg_alloc(&out_msg, msg_size); + if (rv == 0) { message_t * msg_ptr; subscribe_node_cmd_t *out_cmd_ptr; msg_ptr = (message_t *) nng_msg_body(out_msg); @@ -1462,12 +1466,16 @@ static void manager_loop(void *arg) cmd_ptr->grp_config); msg_pipe = src_reg_entity->adapter_pipe; nng_mtx_unlock(manager->adapters_mtx); - msg_size = - msg_inplace_data_get_size(sizeof(unsubscribe_node_cmd_t)); - rv = nng_msg_alloc(&out_msg, msg_size); need_forward = unsub_grp_config_with_pipe( cmd_ptr->grp_config, sub_reg_entity->adapter_pipe); - if (rv == 0 && need_forward == 1) { + if (0 == need_forward) { + break; + } + + msg_size = + msg_inplace_data_get_size(sizeof(unsubscribe_node_cmd_t)); + rv = nng_msg_alloc(&out_msg, msg_size); + if (rv == 0) { message_t * msg_ptr; unsubscribe_node_cmd_t *out_cmd_ptr; msg_ptr = (message_t *) nng_msg_body(out_msg);