From c8ce31a534b094f2a8534c01ce69af0ee2b906af Mon Sep 17 00:00:00 2001 From: crypto-ape <43807588+crypto-ape@users.noreply.github.com> Date: Tue, 2 Apr 2019 12:55:04 +0200 Subject: [PATCH 1/4] fix referencing local stack variable in async thread --- libraries/net/node.cpp | 6 ++++-- libraries/net/node_impl.hxx | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index b2fc5009b7..ba121c165e 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -4909,7 +4909,8 @@ namespace graphene { namespace net { namespace detail { # define INVOKE_AND_COLLECT_STATISTICS(method_name, ...) \ try \ { \ - call_statistics_collector statistics_collector(#method_name, \ + std::shared_ptr statistics_collector = std::make_shared( \ + #method_name, \ &_ ## method_name ## _execution_accumulator, \ &_ ## method_name ## _delay_before_accumulator, \ &_ ## method_name ## _delay_after_accumulator); \ @@ -4941,7 +4942,8 @@ namespace graphene { namespace net { namespace detail { } #else # define INVOKE_AND_COLLECT_STATISTICS(method_name, ...) \ - call_statistics_collector statistics_collector(#method_name, \ + std::shared_ptr statistics_collector = std::make_shared( \ + #method_name, \ &_ ## method_name ## _execution_accumulator, \ &_ ## method_name ## _delay_before_accumulator, \ &_ ## method_name ## _delay_after_accumulator); \ diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 6cebda8f8f..23b9f97411 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -84,16 +84,16 @@ private: public: class actual_execution_measurement_helper { - call_statistics_collector &_collector; + std::shared_ptr _collector; public: actual_execution_measurement_helper(call_statistics_collector& collector) : _collector(collector) { - _collector.starting_execution(); + _collector->starting_execution(); } ~actual_execution_measurement_helper() { - _collector.execution_completed(); + _collector->execution_completed(); } }; call_statistics_collector(const char* method_name, From 376f0317d66f70e0daa3a5c9e29d17544bcdb583 Mon Sep 17 00:00:00 2001 From: crypto-ape <43807588+crypto-ape@users.noreply.github.com> Date: Tue, 2 Apr 2019 12:55:25 +0200 Subject: [PATCH 2/4] explicitly cleanup external library facilities --- libraries/plugins/elasticsearch/elasticsearch_plugin.cpp | 4 ++++ libraries/plugins/es_objects/es_objects.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index c2cfcb9129..0719fc06b4 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -93,6 +93,10 @@ class elasticsearch_plugin_impl elasticsearch_plugin_impl::~elasticsearch_plugin_impl() { + if (curl) { + curl_easy_cleanup(curl); + curl = nullptr; + } return; } diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index 21ae19094e..b3f24f72ac 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -214,6 +214,10 @@ void es_objects_plugin_impl::prepareTemplate(T blockchain_object, string index_n es_objects_plugin_impl::~es_objects_plugin_impl() { + if (curl) { + curl_easy_cleanup(curl); + curl = nullptr; + } return; } From 53af67eb51611b40f445c078107f910dafa4234a Mon Sep 17 00:00:00 2001 From: crypto-ape <43807588+crypto-ape@users.noreply.github.com> Date: Tue, 2 Apr 2019 13:24:50 +0200 Subject: [PATCH 3/4] fix referencing local stack variable in async thread // add missing parameter type change --- libraries/net/node_impl.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 23b9f97411..d755e250b7 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -86,7 +86,7 @@ private: { std::shared_ptr _collector; public: - actual_execution_measurement_helper(call_statistics_collector& collector) : + actual_execution_measurement_helper(std::shared_ptr collector) : _collector(collector) { _collector->starting_execution(); From 3ab22f6b4fd8ce08985387553c4d92f00c4b4fae Mon Sep 17 00:00:00 2001 From: crypto-ape <43807588+crypto-ape@users.noreply.github.com> Date: Tue, 2 Apr 2019 16:18:40 +0200 Subject: [PATCH 4/4] fix referencing local stack variable in async thread // capture shared_ptr by copy --- libraries/net/node.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index ba121c165e..ba11e2d735 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -4920,7 +4920,7 @@ namespace graphene { namespace net { namespace detail { return _node_delegate->method_name(__VA_ARGS__); \ } \ else \ - return _thread->async([&](){ \ + return _thread->async([&, statistics_collector](){ \ call_statistics_collector::actual_execution_measurement_helper helper(statistics_collector); \ return _node_delegate->method_name(__VA_ARGS__); \ }, "invoke " BOOST_STRINGIZE(method_name)).wait(); \ @@ -4953,7 +4953,7 @@ namespace graphene { namespace net { namespace detail { return _node_delegate->method_name(__VA_ARGS__); \ } \ else \ - return _thread->async([&](){ \ + return _thread->async([&, statistics_collector](){ \ call_statistics_collector::actual_execution_measurement_helper helper(statistics_collector); \ return _node_delegate->method_name(__VA_ARGS__); \ }, "invoke " BOOST_STRINGIZE(method_name)).wait()