From 22e1af579fd3b7e157ba5da64c7f2f29a5454276 Mon Sep 17 00:00:00 2001 From: John Plevyak Date: Fri, 10 Apr 2020 19:36:16 +0000 Subject: [PATCH] Fix asan issue. Signed-off-by: John Plevyak --- include/proxy-wasm/wasm.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index d07de3e85..9d914b557 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -134,10 +134,14 @@ class WasmBase : public std::enable_shared_from_this { void addAfterVmCallAction(std::function f) { after_vm_call_actions_.push_back(f); } void doAfterVmCallActions() { - while (!after_vm_call_actions_.empty()) { - auto f = std::move(after_vm_call_actions_.front()); - after_vm_call_actions_.pop_front(); - f(); + // NB: this may be deleted by a delayed function unless prevented. + if (!after_vm_call_actions_.empty()) { + auto self = shared_from_this(); + while (!self->after_vm_call_actions_.empty()) { + auto f = std::move(self->after_vm_call_actions_.front()); + self->after_vm_call_actions_.pop_front(); + f(); + } } }