From e2a6ee77c6acf518036259ca11c18e9abc834b19 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 3 Jun 2016 10:27:03 -0700 Subject: Fix leak of FunctionType from parseFuncType when not already in the module (#563) Pass ownership into the wasm module. --- src/s2wasm.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3