summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2016-06-03 10:27:03 -0700
committerDerek Schuff <dschuff@chromium.org>2016-06-03 10:27:03 -0700
commite2a6ee77c6acf518036259ca11c18e9abc834b19 (patch)
treec3af358b780acf431959ed9b5182ea94c4139fb8 /src
parentf64e1852dc065c17d7c78b43a7cfb7fbe64e3cb4 (diff)
downloadbinaryen-e2a6ee77c6acf518036259ca11c18e9abc834b19.tar.gz
binaryen-e2a6ee77c6acf518036259ca11c18e9abc834b19.tar.bz2
binaryen-e2a6ee77c6acf518036259ca11c18e9abc834b19.zip
Fix leak of FunctionType from parseFuncType when not already in the module (#563)
Pass ownership into the wasm module.
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index d24f5ef46..fea40e749 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -496,9 +496,15 @@ class S2WasmBuilder {
decl->result = getType();
}
while (*s && skipComma()) decl->params.push_back(getType());
+ decl->name = "FUNCSIG$" + getSig(decl.get());
- FunctionType *ty = wasm->checkFunctionType(getSig(decl.get()));
- if (!ty) ty = decl.release();
+ FunctionType *ty = wasm->checkFunctionType(decl->name);
+ if (!ty) {
+ // The wasm module takes ownership of the FunctionType if we insert it.
+ // Otherwise it's already in the module and ours is freed.
+ ty = decl.release();
+ wasm->addFunctionType(ty);
+ }
linkerObj->addExternType(name, ty);
}