Skip to content

Commit ca141b9

Browse files
authored
Fix getRootContext(). (#79)
Previously, getRootContext() was adding an empty entry to the map. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
1 parent d54b379 commit ca141b9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/proxy-wasm/wasm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
5959
std::string_view vm_key() const { return vm_key_; }
6060
WasmVm *wasm_vm() const { return wasm_vm_.get(); }
6161
ContextBase *vm_context() const { return vm_context_.get(); }
62-
ContextBase *getRootContext(std::string_view root_id) {
63-
return root_contexts_[std::string(root_id)].get();
64-
}
62+
ContextBase *getRootContext(std::string_view root_id);
6563
ContextBase *getOrCreateRootContext(const std::shared_ptr<PluginBase> &plugin);
6664
ContextBase *getContext(uint32_t id) {
6765
auto it = contexts_.find(id);

src/wasm.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ bool WasmBase::initialize(const std::string &code, bool allow_precompiled) {
314314
return !isFailed();
315315
}
316316

317+
ContextBase *WasmBase::getRootContext(std::string_view root_id) {
318+
auto it = root_contexts_.find(std::string(root_id));
319+
if (it == root_contexts_.end()) {
320+
return nullptr;
321+
}
322+
return it->second.get();
323+
}
324+
317325
ContextBase *WasmBase::getOrCreateRootContext(const std::shared_ptr<PluginBase> &plugin) {
318326
auto root_context = getRootContext(plugin->root_id_);
319327
if (!root_context) {

0 commit comments

Comments
 (0)