Skip to content

Commit caa1736

Browse files
Fix memory leak of ISeqAllocator
1 parent c56613f commit caa1736

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

Sources/WasmKit/ModuleParser.swift

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,39 +125,19 @@ func parseModule<Stream: ByteStream>(stream: Stream, features: WasmFeatureSet =
125125
memoryTypes: module.memories.map { $0.type },
126126
tables: module.tables
127127
)
128+
let allocator = module.allocator
128129
let functions = codes.enumerated().map { [hasDataCount = parser.hasDataCount, features] index, code in
129130
let funcTypeIndex = typeIndices[index]
130131
let funcType = module.types[Int(funcTypeIndex)]
131132
return GuestFunction(
132-
type: typeIndices[index], locals: code.locals, allocator: module.allocator,
133+
type: typeIndices[index], locals: code.locals, allocator: allocator,
133134
body: {
134-
let enableAssert: Bool
135-
#if ASSERT
136-
enableAssert = true
137-
#else
138-
enableAssert = false
139-
#endif
140-
141135
var translator = InstructionTranslator(
142-
allocator: module.allocator,
136+
allocator: allocator,
143137
module: translatorContext,
144138
type: funcType, locals: code.locals
145139
)
146140

147-
if enableAssert && !_isFastAssertConfiguration() {
148-
let globalFuncIndex = module.imports.count + index
149-
print("🚀 Starting Translation for code[\(globalFuncIndex)] (\(funcType))")
150-
var tracing = InstructionTracingVisitor(trace: {
151-
print("🍵 code[\(globalFuncIndex)] Translating \($0)")
152-
}, visitor: translator)
153-
try WasmParser.parseExpression(
154-
bytes: Array(code.expression),
155-
features: features, hasDataCount: hasDataCount,
156-
visitor: &tracing
157-
)
158-
let newISeq = tracing.visitor.finalize()
159-
return newISeq
160-
}
161141
try WasmParser.parseExpression(
162142
bytes: Array(code.expression),
163143
features: features, hasDataCount: hasDataCount,

0 commit comments

Comments
 (0)