summaryrefslogtreecommitdiff
path: root/src/passes/LegalizeJSInterface.cpp
diff options
context:
space:
mode:
authorPaweł Bylica <chfast@gmail.com>2019-01-10 17:23:08 +0100
committerAlon Zakai <alonzakai@gmail.com>2019-01-10 08:23:08 -0800
commit51a481f6ed9e39b284421778b63b265eca6c1b58 (patch)
treecf55edd7cc08dddc18900fe4f8badb4b39dbf837 /src/passes/LegalizeJSInterface.cpp
parente71506165996f7a12cd54361761bc88c7f883cd2 (diff)
downloadbinaryen-51a481f6ed9e39b284421778b63b265eca6c1b58.tar.gz
binaryen-51a481f6ed9e39b284421778b63b265eca6c1b58.tar.bz2
binaryen-51a481f6ed9e39b284421778b63b265eca6c1b58.zip
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.
Diffstat (limited to 'src/passes/LegalizeJSInterface.cpp')
-rw-r--r--src/passes/LegalizeJSInterface.cpp6
1 files changed, 3 insertions, 3 deletions
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<FunctionType>();
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);