This is an automated email from the ASF dual-hosted git repository.

jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/main by this push:
     new c33dc69  DISPATCH-1962 Fix leak of qdr_core_subscribe (#1051)
c33dc69 is described below

commit c33dc697ad046a26ec92ca51bf091d9ec456c9e3
Author: Jiri DanÄ›k <[email protected]>
AuthorDate: Thu May 6 18:19:25 2021 +0200

    DISPATCH-1962 Fix leak of qdr_core_subscribe (#1051)
---
 src/router_core/modules/mobile_sync/mobile.c |  5 ++-
 src/router_core/router_core.c                | 47 ++++++++++++++--------------
 tests/lsan.supp                              |  4 ---
 3 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/src/router_core/modules/mobile_sync/mobile.c 
b/src/router_core/modules/mobile_sync/mobile.c
index d216c3d..866e17a 100644
--- a/src/router_core/modules/mobile_sync/mobile.c
+++ b/src/router_core/modules/mobile_sync/mobile.c
@@ -939,9 +939,8 @@ static void qcm_mobile_sync_final_CT(void *module_context)
     qdrc_event_unsubscribe_CT(msync->core, msync->event_sub);
     qdr_core_timer_free_CT(msync->core, msync->timer);
 
-    //
-    // Don't explicitly unsubscribe the addresses, these are already gone at 
module-final time.
-    //
+    qdr_core_unsubscribe(msync->message_sub1);
+    qdr_core_unsubscribe(msync->message_sub2);
 
     free(msync);
 }
diff --git a/src/router_core/router_core.c b/src/router_core/router_core.c
index 343de9b..d5ba6e1 100644
--- a/src/router_core/router_core.c
+++ b/src/router_core/router_core.c
@@ -152,32 +152,9 @@ void qdr_core_free(qdr_core_t *core)
     core->router_id = 0;
     core->router_area = 0;
 
-    // discard any left over actions
-
-    qdr_action_list_t  action_list;
-    DEQ_MOVE(core->action_list, action_list);
-    DEQ_APPEND(action_list, core->action_list_background);
-    qdr_action_t *action = DEQ_HEAD(action_list);
-    while (action) {
-        DEQ_REMOVE_HEAD(action_list);
-        action->action_handler(core, action, true);
-        free_qdr_action_t(action);
-        action = DEQ_HEAD(action_list);
-    }
-
-    // Drain the general work lists
-    qdr_general_handler(core);
-
     //
     // Free the core resources
     //
-    sys_thread_free(core->thread);
-    sys_cond_free(core->action_cond);
-    sys_mutex_free(core->action_lock);
-    sys_mutex_free(core->work_lock);
-    sys_mutex_free(core->id_lock);
-    qd_timer_free(core->work_timer);
-
     for (int i = 0; i <= QD_TREATMENT_LINK_BALANCED; ++i) {
         if (core->forwarders[i]) {
             free(core->forwarders[i]);
@@ -307,8 +284,25 @@ void qdr_core_free(qdr_core_t *core)
     // at this point all the conn identifiers have been freed
     qd_hash_free(core->conn_id_hash);
 
+    // finalize modules while we can still submit new actions
     qdr_modules_finalize(core);
 
+    // discard any left over actions
+
+    qdr_action_list_t  action_list;
+    DEQ_MOVE(core->action_list, action_list);
+    DEQ_APPEND(action_list, core->action_list_background);
+    qdr_action_t *action = DEQ_HEAD(action_list);
+    while (action) {
+        DEQ_REMOVE_HEAD(action_list);
+        action->action_handler(core, action, true);
+        free_qdr_action_t(action);
+        action = DEQ_HEAD(action_list);
+    }
+
+    // Drain the general work lists
+    qdr_general_handler(core);
+
     qdr_agent_free(core->mgmt_agent);
 
     if (core->routers_by_mask_bit)       free(core->routers_by_mask_bit);
@@ -317,6 +311,13 @@ void qdr_core_free(qdr_core_t *core)
     if (core->neighbor_free_mask)        
qd_bitmask_free(core->neighbor_free_mask);
     if (core->rnode_conns_by_mask_bit)   free(core->rnode_conns_by_mask_bit);
 
+    sys_thread_free(core->thread);
+    sys_cond_free(core->action_cond);
+    sys_mutex_free(core->action_lock);
+    sys_mutex_free(core->work_lock);
+    sys_mutex_free(core->id_lock);
+    qd_timer_free(core->work_timer);
+
     free(core);
 }
 
diff --git a/tests/lsan.supp b/tests/lsan.supp
index c27cf97..49f4f9b 100644
--- a/tests/lsan.supp
+++ b/tests/lsan.supp
@@ -35,10 +35,6 @@ leak:^pni_init_default_logger$
 # DISPATCH-1844 - shutdown leak
 leak:sys_mutex
 
-# expected, not a bug:
-#
-leak:qdr_core_subscribe
-
 # Ubuntu 16.04 (Xenial)
 #
 leak:_ctypes_alloc_format_string

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to