From d13267ba5d99a8b455b58db0d5fc0760e0c8944b Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Tue, 18 Jun 2024 13:52:09 -0700 Subject: [PATCH] fix leaks with unique_ptr --- src/wasm-binary.h | 2 +- src/wasm/wasm-binary.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wasm-binary.h b/src/wasm-binary.h index f7d57f5c9f2..3870ccf7faa 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1583,7 +1583,7 @@ class WasmBinaryReader { void readVars(); std::map exportIndices; - std::vector exportOrder; + std::vector> exportOrder; void readExports(); // The strings in the strings section (which are referred to by StringConst). diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 658cfe29230..0dcc7125412 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2682,10 +2682,10 @@ void WasmBinaryReader::readFunctions() { } endOfFunction = pos + size; - auto* func = new Function; + auto func = std::make_unique(); func->name = Name::fromInt(i); func->type = getTypeByFunctionIndex(numImports + i); - currFunction = func; + currFunction = func.get(); if (DWARF) { func->funcLocation = BinaryLocations::FunctionLocations{ @@ -2749,12 +2749,12 @@ void WasmBinaryReader::readFunctions() { } } - TypeUpdating::handleNonDefaultableLocals(func, wasm); + TypeUpdating::handleNonDefaultableLocals(func.get(), wasm); std::swap(func->epilogLocation, debugLocation); currFunction = nullptr; debugLocation.clear(); - wasm.addFunction(func); + wasm.addFunction(std::move(func)); } BYN_TRACE(" end function bodies\n"); } @@ -2786,15 +2786,15 @@ void WasmBinaryReader::readExports() { std::unordered_set names; for (size_t i = 0; i < num; i++) { BYN_TRACE("read one\n"); - auto curr = new Export; + auto curr = std::make_unique(); curr->name = getInlineString(); if (!names.emplace(curr->name).second) { throwError("duplicate export name"); } curr->kind = (ExternalKind)getU32LEB(); auto index = getU32LEB(); - exportIndices[curr] = index; - exportOrder.push_back(curr); + exportIndices[curr.get()] = index; + exportOrder.push_back(std::move(curr)); } } @@ -3250,8 +3250,8 @@ void WasmBinaryReader::processNames() { wasm.start = getFunctionName(startIndex); } - for (auto* curr : exportOrder) { - auto index = exportIndices[curr]; + for (auto& curr : exportOrder) { + auto index = exportIndices[curr.get()]; switch (curr->kind) { case ExternalKind::Function: { curr->value = getFunctionName(index); @@ -3272,7 +3272,7 @@ void WasmBinaryReader::processNames() { default: throwError("bad export kind"); } - wasm.addExport(curr); + wasm.addExport(std::move(curr)); } for (auto& [index, refs] : functionRefs) {