diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-06-23 15:28:10 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-06-23 15:28:10 +0000 |
| commit | 49381bee2e466d6d43025fb79db2b663dd4f6ae1 (patch) | |
| tree | ad9255f37752ede85783451592ba1e31142eb2b7 | |
| parent | e7800cab8284c98b42ddb7b59c03e26e5194e082 (diff) | |
| download | bcm5719-llvm-49381bee2e466d6d43025fb79db2b663dd4f6ae1.tar.gz bcm5719-llvm-49381bee2e466d6d43025fb79db2b663dd4f6ae1.zip | |
[Option] Plug a leak when move-assigning an InputArgList.
The class has a non-trivial dtor so we have to clean up before we move
in new members. Remove misleading comment as a default move assignment
operator will never be synthesized for this class.
llvm-svn: 240417
| -rw-r--r-- | llvm/include/llvm/Option/ArgList.h | 8 | ||||
| -rw-r--r-- | llvm/lib/Option/ArgList.cpp | 12 |
2 files changed, 11 insertions, 9 deletions
diff --git a/llvm/include/llvm/Option/ArgList.h b/llvm/include/llvm/Option/ArgList.h index e29cf24661a..ef4005761b7 100644 --- a/llvm/include/llvm/Option/ArgList.h +++ b/llvm/include/llvm/Option/ArgList.h @@ -325,22 +325,24 @@ private: /// The number of original input argument strings. unsigned NumInputArgStrings; + /// Release allocated arguments. + void releaseMemory(); + public: InputArgList(const char* const *ArgBegin, const char* const *ArgEnd); - // Default move operations implemented for the convenience of MSVC. Nothing - // special here. InputArgList(InputArgList &&RHS) : ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)), SynthesizedStrings(std::move(RHS.SynthesizedStrings)), NumInputArgStrings(RHS.NumInputArgStrings) {} InputArgList &operator=(InputArgList &&RHS) { + releaseMemory(); ArgList::operator=(std::move(RHS)); ArgStrings = std::move(RHS.ArgStrings); SynthesizedStrings = std::move(RHS.SynthesizedStrings); NumInputArgStrings = RHS.NumInputArgStrings; return *this; } - ~InputArgList(); + ~InputArgList() { releaseMemory(); } const char *getArgString(unsigned Index) const override { return ArgStrings[Index]; diff --git a/llvm/lib/Option/ArgList.cpp b/llvm/lib/Option/ArgList.cpp index e29b62f74dc..a74ead6b358 100644 --- a/llvm/lib/Option/ArgList.cpp +++ b/llvm/lib/Option/ArgList.cpp @@ -315,18 +315,18 @@ const char *ArgList::GetOrMakeJoinedArgString(unsigned Index, // +void InputArgList::releaseMemory() { + // An InputArgList always owns its arguments. + for (Arg *A : *this) + delete A; +} + InputArgList::InputArgList(const char* const *ArgBegin, const char* const *ArgEnd) : NumInputArgStrings(ArgEnd - ArgBegin) { ArgStrings.append(ArgBegin, ArgEnd); } -InputArgList::~InputArgList() { - // An InputArgList always owns its arguments. - for (iterator it = begin(), ie = end(); it != ie; ++it) - delete *it; -} - unsigned InputArgList::MakeIndex(StringRef String0) const { unsigned Index = ArgStrings.size(); |

