From 51a481f6ed9e39b284421778b63b265eca6c1b58 Mon Sep 17 00:00:00 2001 From: Paweł Bylica Date: Thu, 10 Jan 2019 17:23:08 +0100 Subject: Require unique_ptr to Module::addFunctionType() (#1672) This fixes the memory leak in WasmBinaryBuilder::readSignatures() caused probably the exception thrown there before the FunctionType object is safe. This also makes it clear that the Module becomes the owner of the FunctionType objects. --- src/passes/LegalizeJSInterface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/passes/LegalizeJSInterface.cpp') diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index 9d223390e..8a68ccc88 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -189,7 +189,7 @@ private: // wasm calls the import, so it must call a stub that calls the actual legal JS import Name makeLegalStubForCalledImport(Function* im, Module* module) { Builder builder(*module); - auto* type = new FunctionType; + auto type = make_unique(); type->name = Name(std::string("legaltype$") + im->name.str); auto* legal = new Function; legal->name = Name(std::string("legalimport$") + im->name.str); @@ -236,13 +236,13 @@ private: type->result = imFunctionType->result; } func->result = imFunctionType->result; - FunctionTypeUtils::fillFunction(legal, type); + FunctionTypeUtils::fillFunction(legal, type.get()); if (!module->getFunctionOrNull(func->name)) { module->addFunction(func); } if (!module->getFunctionTypeOrNull(type->name)) { - module->addFunctionType(type); + module->addFunctionType(std::move(type)); } if (!module->getFunctionOrNull(legal->name)) { module->addFunction(legal); -- cgit v1.2.3