diff --git a/source/extensions/access_loggers/wasm/config.cc b/source/extensions/access_loggers/wasm/config.cc index 33e767374361e..cc50a4e59789b 100644 --- a/source/extensions/access_loggers/wasm/config.cc +++ b/source/extensions/access_loggers/wasm/config.cc @@ -30,7 +30,8 @@ WasmAccessLogFactory::createAccessLogInstance(const Protobuf::Message& proto_con auto configuration = std::make_shared(config.configuration()); auto tls_slot = context.threadLocal().allocateSlot(); if (config.has_vm_config()) { - // Create a base WASM to verify that the code loads before setting/cloning the for the individual threads. + // Create a base WASM to verify that the code loads before setting/cloning the for the + // individual threads. auto base_wasm = Common::Wasm::createWasm(id, config.vm_config(), context.clusterManager(), context.dispatcher(), context.api()); // NB: the Slot set() call doesn't complete inline, so all arguments must outlive this call. diff --git a/source/extensions/common/wasm/wasm.cc b/source/extensions/common/wasm/wasm.cc index 8912876df531a..bafba6c04b7ff 100644 --- a/source/extensions/common/wasm/wasm.cc +++ b/source/extensions/common/wasm/wasm.cc @@ -4,7 +4,6 @@ #include #include -#include #include "envoy/common/exception.h" #include "envoy/config/wasm/v2/wasm.pb.validate.h" @@ -1020,7 +1019,8 @@ void Wasm::getFunctions() { } Wasm::Wasm(const Wasm& wasm) - : cluster_manager_(wasm.cluster_manager_), dispatcher_(wasm.dispatcher_) { + : std::enable_shared_from_this(), cluster_manager_(wasm.cluster_manager_), + dispatcher_(wasm.dispatcher_) { wasm_vm_ = wasm.wasmVm()->clone(); general_context_ = createContext(); getFunctions(); diff --git a/source/extensions/common/wasm/wasm.h b/source/extensions/common/wasm/wasm.h index 06f61a6b107e6..b5bfb0d1204a5 100644 --- a/source/extensions/common/wasm/wasm.h +++ b/source/extensions/common/wasm/wasm.h @@ -306,7 +306,7 @@ class Wasm : public Envoy::Server::Wasm, uint32_t next_context_id_ = 0; std::unique_ptr wasm_vm_; std::shared_ptr general_context_; // Context unrelated to any specific stream. - std::function tick_; + std::function tick_; std::chrono::milliseconds tick_period_; Event::TimerPtr timer_; diff --git a/source/extensions/common/wasm/wavm/wavm.cc b/source/extensions/common/wasm/wavm/wavm.cc index 135c8c101e677..8d87f5d27971f 100644 --- a/source/extensions/common/wasm/wavm/wavm.cc +++ b/source/extensions/common/wasm/wavm/wavm.cc @@ -215,7 +215,7 @@ Wavm::~Wavm() { } std::unique_ptr Wavm::clone() { - auto wavm = new Wavm(); + auto wavm = std::make_unique(); wavm->compartment_ = WAVM::Runtime::cloneCompartment(compartment_); wavm->memory_ = WAVM::Runtime::remapToClonedCompartment(memory_, wavm->compartment_); wavm->context_ = WAVM::Runtime::createContext(wavm->compartment_); @@ -223,7 +223,7 @@ std::unique_ptr Wavm::clone() { WAVM::Runtime::remapToClonedCompartment(envoyModuleInstance_, wavm->compartment_); wavm->moduleInstance_ = WAVM::Runtime::remapToClonedCompartment(moduleInstance_, wavm->compartment_); - return std::unique_ptr(wavm); + return wavm; } bool Wavm::initialize(const std::string& code, absl::string_view name, bool allow_precompiled) { diff --git a/source/extensions/filters/http/wasm/config.cc b/source/extensions/filters/http/wasm/config.cc index daa802562f650..d398a4da9178e 100644 --- a/source/extensions/filters/http/wasm/config.cc +++ b/source/extensions/filters/http/wasm/config.cc @@ -17,7 +17,7 @@ namespace Wasm { Http::FilterFactoryCb WasmFilterConfig::createFilterFactoryFromProtoTyped( const envoy::config::filter::http::wasm::v2::Wasm& proto_config, const std::string&, Server::Configuration::FactoryContext& context) { - FilterConfigConstSharedPtr filter_config(new FilterConfig{proto_config, context}); + auto filter_config = std::make_shared(proto_config, context); return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void { auto filter = filter_config->createFilter(); callbacks.addStreamFilter(filter); diff --git a/source/extensions/filters/http/wasm/wasm_filter.cc b/source/extensions/filters/http/wasm/wasm_filter.cc index 46d97f8d8252b..16c8ee3181872 100644 --- a/source/extensions/filters/http/wasm/wasm_filter.cc +++ b/source/extensions/filters/http/wasm/wasm_filter.cc @@ -20,7 +20,8 @@ FilterConfig::FilterConfig(const envoy::config::filter::http::wasm::v2::Wasm& co auto id = config.id(); auto configuration = std::make_shared(config.configuration()); if (config.has_vm_config()) { - // Create a base WASM to verify that the code loads before setting/cloning the for the individual threads. + // Create a base WASM to verify that the code loads before setting/cloning the for the + // individual threads. auto base_wasm = Common::Wasm::createWasm(id, config.vm_config(), context.clusterManager(), context.dispatcher(), context.api()); // NB: the Slot set() call doesn't complete inline, so all arguments must outlive this call. diff --git a/source/extensions/filters/http/wasm/wasm_filter.h b/source/extensions/filters/http/wasm/wasm_filter.h index 03b86ef134d79..fefc6e71a296f 100644 --- a/source/extensions/filters/http/wasm/wasm_filter.h +++ b/source/extensions/filters/http/wasm/wasm_filter.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "envoy/config/filter/http/wasm/v2/wasm.pb.validate.h" #include "envoy/http/filter.h" @@ -18,10 +18,6 @@ namespace Wasm { using Envoy::Extensions::Common::Wasm::Context; using Envoy::Extensions::Common::Wasm::Wasm; -class FilterConfig; - -typedef std::shared_ptr FilterConfigConstSharedPtr; - class FilterConfig : Logger::Loggable { public: FilterConfig(const envoy::config::filter::http::wasm::v2::Wasm& proto_config, @@ -33,6 +29,8 @@ class FilterConfig : Logger::Loggable { ThreadLocal::SlotPtr tls_slot_; }; +typedef std::shared_ptr FilterConfigSharedPtr; + } // namespace Wasm } // namespace HttpFilters } // namespace Extensions diff --git a/source/extensions/wasm/config.cc b/source/extensions/wasm/config.cc index 41eb29ce7b584..601c4208acba9 100644 --- a/source/extensions/wasm/config.cc +++ b/source/extensions/wasm/config.cc @@ -18,7 +18,8 @@ static const std::string INLINE_STRING = ""; Server::WasmSharedPtr WasmFactory::createWasm(const envoy::config::wasm::v2::WasmConfig& config, Server::Configuration::WasmFactoryContext& context) { - // Create a base WASM to verify that the code loads before setting/cloning the for the individual threads. + // Create a base WASM to verify that the code loads before setting/cloning the for the individual + // threads. auto base_wasm = Common::Wasm::createWasm(config.id(), config.vm_config(), context.clusterManager(), context.dispatcher(), context.api());