From d2d788662ab0fe29d7b1a44a53fe7a8981d09cdc Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 13 Jun 2022 17:23:13 +0000 Subject: [PATCH] node: wait for event loop to stop before freeing objects This prevents segfaults during shutdown. --- CHANGELOG.md | 1 + node/src/module.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc45d1c74..700e500e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes - set a default error if NDN does not provide an error - python: avoid exceptions when messages/contacts/chats are compared with `None` +- node: wait for the event loop to stop before destroying contexts #3431 ### API-Changes - python: added `Message.get_status_updates()` #3416 diff --git a/node/src/module.c b/node/src/module.c index 01ec19f54..b1ff9cca2 100644 --- a/node/src/module.c +++ b/node/src/module.c @@ -371,6 +371,11 @@ NAPI_METHOD(dcn_context_unref) { TRACE("Unrefing dc_context"); dcn_context->gc = 1; + dc_stop_io(dcn_context->dc_context); + if (dcn_context->event_handler_thread != 0) { + uv_thread_join(&dcn_context->event_handler_thread); + dcn_context->event_handler_thread = 0; + } dc_context_unref(dcn_context->dc_context); dcn_context->dc_context = NULL; @@ -2922,6 +2927,11 @@ NAPI_METHOD(dcn_accounts_unref) { TRACE("Unrefing dc_accounts"); dcn_accounts->gc = 1; + dc_accounts_stop_io(dcn_accounts->dc_accounts); + if (dcn_accounts->event_handler_thread != 0) { + uv_thread_join(&dcn_accounts->event_handler_thread); + dcn_accounts->event_handler_thread = 0; + } dc_accounts_unref(dcn_accounts->dc_accounts); dcn_accounts->dc_accounts = NULL;