summaryrefslogtreecommitdiff
path: root/src/wasm-s-parser.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-27 19:25:15 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-27 19:25:15 -0700
commit6a6bdc1cef5ec35cb9f7caf6e10ec76ee1107d0d (patch)
tree9ed1b23b55c86f8fa1aee285bfdde9d47c2f1ae8 /src/wasm-s-parser.h
parent4a85f62e8a83117a081e9691d8830b6a7a876d1d (diff)
parentf0a4f15dc27ffff9505503a8168854b7662b2657 (diff)
downloadbinaryen-6a6bdc1cef5ec35cb9f7caf6e10ec76ee1107d0d.tar.gz
binaryen-6a6bdc1cef5ec35cb9f7caf6e10ec76ee1107d0d.tar.bz2
binaryen-6a6bdc1cef5ec35cb9f7caf6e10ec76ee1107d0d.zip
Merge pull request #403 from WebAssembly/leaks
Fix leaks and enable leak checks
Diffstat (limited to 'src/wasm-s-parser.h')
-rw-r--r--src/wasm-s-parser.h34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index b6a532790..a2a0e0027 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -52,7 +52,7 @@ int unhex(char c) {
//
class Element {
- typedef std::vector<Element*> List;
+ typedef ArenaVector<Element*> List;
bool isList_;
List list_;
@@ -60,8 +60,7 @@ class Element {
bool dollared_;
public:
- Element() : isList_(true) {}
- Element(MixedArena& allocator) : Element() {}
+ Element(MixedArena& allocator) : isList_(true), list_(allocator) {}
bool isList() { return isList_; }
bool isStr() { return !isList_; }
@@ -317,7 +316,7 @@ private:
}
// function parsing state
- Function *currFunction = nullptr;
+ std::unique_ptr<Function> currFunction;
std::map<Name, WasmType> currLocalTypes;
size_t localIndex; // params and vars
size_t otherIndex;
@@ -363,12 +362,12 @@ private:
Name type;
Block* autoBlock = nullptr; // we may need to add a block for the very top level
auto makeFunction = [&]() {
- currFunction = Builder(wasm).makeFunction(
+ currFunction = std::unique_ptr<Function>(Builder(wasm).makeFunction(
name,
std::move(params),
result,
std::move(vars)
- );
+ ));
};
for (;i < s.size(); i++) {
Element& curr = *s[i];
@@ -439,10 +438,9 @@ private:
assert(currFunction->result == result);
currFunction->body = body;
currFunction->type = type;
- wasm.addFunction(currFunction);
+ wasm.addFunction(currFunction.release());
currLocalTypes.clear();
labelStack.clear();
- currFunction = nullptr;
}
WasmType stringToWasmType(IString str, bool allowError=false, bool prefix=false) {
@@ -1068,7 +1066,7 @@ private:
Element& curr = *s[i];
assert(curr[0]->str() == SEGMENT);
const char *input = curr[2]->c_str();
- char *data = (char*)malloc(strlen(input)); // over-allocated, since escaping collapses, but whatever
+ char data[strlen(input)];
char *write = data;
while (1) {
if (input[0] == 0) break;
@@ -1102,7 +1100,7 @@ private:
*write++ = input[0];
input++;
}
- wasm.memory.segments.emplace_back(atoi(curr[1]->c_str()), data, write - data);
+ wasm.memory.segments.emplace_back(atoi(curr[1]->c_str()), (const char*)data, write - data);
i++;
}
}
@@ -1114,14 +1112,14 @@ private:
wasm.memory.exportName = s[1]->str();
return;
}
- auto ex = allocator.alloc<Export>();
+ std::unique_ptr<Export> ex = make_unique<Export>();
ex->name = s[1]->str();
ex->value = s[2]->str();
- wasm.addExport(ex);
+ wasm.addExport(ex.release());
}
void parseImport(Element& s) {
- auto im = allocator.alloc<Import>();
+ std::unique_ptr<Import> im = make_unique<Import>();
size_t i = 1;
if (s.size() > 3 && s[3]->isStr()) {
im->name = s[i++]->str();
@@ -1132,7 +1130,7 @@ private:
im->module = s[i++]->str();
if (!s[i]->isStr()) onError();
im->base = s[i++]->str();
- FunctionType* type = allocator.alloc<FunctionType>();
+ std::unique_ptr<FunctionType> type = make_unique<FunctionType>();
if (s.size() > i) {
Element& params = *s[i];
IString id = params[0]->str();
@@ -1155,8 +1153,8 @@ private:
type->result = stringToWasmType(result[1]->str());
}
}
- im->type = ensureFunctionType(getSig(type), &wasm);
- wasm.addImport(im);
+ im->type = ensureFunctionType(getSig(type.get()), &wasm);
+ wasm.addImport(im.release());
}
void parseTable(Element& s) {
@@ -1166,7 +1164,7 @@ private:
}
void parseType(Element& s) {
- auto type = allocator.alloc<FunctionType>();
+ std::unique_ptr<FunctionType> type = make_unique<FunctionType>();
size_t i = 1;
if (s[i]->isStr()) {
type->name = s[i]->str();
@@ -1184,7 +1182,7 @@ private:
type->result = stringToWasmType(curr[1]->str());
}
}
- wasm.addFunctionType(type);
+ wasm.addFunctionType(type.release());
}
};