Skip to content

Commit

Permalink
fix leaks with unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
tlively committed Jun 18, 2024
1 parent 11f2969 commit d13267b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ class WasmBinaryReader {
void readVars();

std::map<Export*, Index> exportIndices;
std::vector<Export*> exportOrder;
std::vector<std::unique_ptr<Export>> exportOrder;
void readExports();

// The strings in the strings section (which are referred to by StringConst).
Expand Down
20 changes: 10 additions & 10 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2682,10 +2682,10 @@ void WasmBinaryReader::readFunctions() {
}
endOfFunction = pos + size;

auto* func = new Function;
auto func = std::make_unique<Function>();
func->name = Name::fromInt(i);
func->type = getTypeByFunctionIndex(numImports + i);
currFunction = func;
currFunction = func.get();

if (DWARF) {
func->funcLocation = BinaryLocations::FunctionLocations{
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -2786,15 +2786,15 @@ void WasmBinaryReader::readExports() {
std::unordered_set<Name> names;
for (size_t i = 0; i < num; i++) {
BYN_TRACE("read one\n");
auto curr = new Export;
auto curr = std::make_unique<Export>();
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));
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit d13267b

Please sign in to comment.