summaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/s2wasm.h10
-rw-r--r--test/dot_s/indirect-import.wast6
2 files changed, 11 insertions, 5 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);
}
diff --git a/test/dot_s/indirect-import.wast b/test/dot_s/indirect-import.wast
index 8ffeea168..f3a989461 100644
--- a/test/dot_s/indirect-import.wast
+++ b/test/dot_s/indirect-import.wast
@@ -1,10 +1,10 @@
(module
(memory 1)
(export "memory" memory)
- (type $FUNCSIG$ijidf (func (param i64 i32 f64 f32) (result i32)))
- (type $FUNCSIG$v (func))
- (type $FUNCSIG$vj (func (param i64)))
(type $FUNCSIG$fd (func (param f64) (result f32)))
+ (type $FUNCSIG$vj (func (param i64)))
+ (type $FUNCSIG$v (func))
+ (type $FUNCSIG$ijidf (func (param i64 i32 f64 f32) (result i32)))
(type $FUNCSIG$vi (func (param i32)))
(import $extern_ijidf "env" "extern_ijidf" (param i64 i32 f64 f32) (result i32))
(import $extern_v "env" "extern_v")