diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-27 13:24:09 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-27 16:59:18 -0700 |
commit | 90bdf763537815a523d0dbe75a67e7f0b14b0d9e (patch) | |
tree | 2fe32e380cabbc3f7e1c5916a8d2ceec90f44fd3 /src/emscripten-optimizer | |
parent | 2c8e64a91197beed1792e65a9d409ca50e12697c (diff) | |
download | binaryen-90bdf763537815a523d0dbe75a67e7f0b14b0d9e.tar.gz binaryen-90bdf763537815a523d0dbe75a67e7f0b14b0d9e.tar.bz2 binaryen-90bdf763537815a523d0dbe75a67e7f0b14b0d9e.zip |
do not leak in IStringSet
Diffstat (limited to 'src/emscripten-optimizer')
-rw-r--r-- | src/emscripten-optimizer/istring.h | 4 | ||||
-rw-r--r-- | src/emscripten-optimizer/parser.cpp | 26 |
2 files changed, 16 insertions, 14 deletions
diff --git a/src/emscripten-optimizer/istring.h b/src/emscripten-optimizer/istring.h index 149f77d23..e47361eeb 100644 --- a/src/emscripten-optimizer/istring.h +++ b/src/emscripten-optimizer/istring.h @@ -149,11 +149,13 @@ namespace cashew { // IStringSet class IStringSet : public std::unordered_set<IString> { + std::vector<char> data; public: IStringSet() {} IStringSet(const char *init) { // comma-delimited list int size = strlen(init) + 1; - char *curr = new char[size]; // leaked! + data.resize(size); + char *curr = &data[0]; strncpy(curr, init, size); while (1) { char *end = strchr(curr, ' '); diff --git a/src/emscripten-optimizer/parser.cpp b/src/emscripten-optimizer/parser.cpp index b8297fc29..ef2891941 100644 --- a/src/emscripten-optimizer/parser.cpp +++ b/src/emscripten-optimizer/parser.cpp @@ -121,19 +121,19 @@ static std::vector<std::unordered_map<IString, int>> precedences; // op, type => struct Init { Init() { // operators, rtl, type - operatorClasses.push_back(OperatorClass(".", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("! ~ + -", true, OperatorClass::Prefix)); - operatorClasses.push_back(OperatorClass("* / %", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("+ -", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("<< >> >>>", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("< <= > >=", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("== !=", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("&", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("^", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("|", false, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass("? :", true, OperatorClass::Tertiary)); - operatorClasses.push_back(OperatorClass("=", true, OperatorClass::Binary)); - operatorClasses.push_back(OperatorClass(",", true, OperatorClass::Binary)); + operatorClasses.emplace_back(".", false, OperatorClass::Binary); + operatorClasses.emplace_back("! ~ + -", true, OperatorClass::Prefix); + operatorClasses.emplace_back("* / %", false, OperatorClass::Binary); + operatorClasses.emplace_back("+ -", false, OperatorClass::Binary); + operatorClasses.emplace_back("<< >> >>>", false, OperatorClass::Binary); + operatorClasses.emplace_back("< <= > >=", false, OperatorClass::Binary); + operatorClasses.emplace_back("== !=", false, OperatorClass::Binary); + operatorClasses.emplace_back("&", false, OperatorClass::Binary); + operatorClasses.emplace_back("^", false, OperatorClass::Binary); + operatorClasses.emplace_back("|", false, OperatorClass::Binary); + operatorClasses.emplace_back("? :", true, OperatorClass::Tertiary); + operatorClasses.emplace_back("=", true, OperatorClass::Binary); + operatorClasses.emplace_back(",", true, OperatorClass::Binary); precedences.resize(OperatorClass::Tertiary + 1); |