[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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240417 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2015-06-23 15:28:10 +00:00
parent 9492ec55bd
commit 896353d663
2 changed files with 11 additions and 9 deletions

View File

@ -325,22 +325,24 @@ private:
/// The number of original input argument strings. /// The number of original input argument strings.
unsigned NumInputArgStrings; unsigned NumInputArgStrings;
/// Release allocated arguments.
void releaseMemory();
public: public:
InputArgList(const char* const *ArgBegin, const char* const *ArgEnd); InputArgList(const char* const *ArgBegin, const char* const *ArgEnd);
// Default move operations implemented for the convenience of MSVC. Nothing
// special here.
InputArgList(InputArgList &&RHS) InputArgList(InputArgList &&RHS)
: ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)), : ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)),
SynthesizedStrings(std::move(RHS.SynthesizedStrings)), SynthesizedStrings(std::move(RHS.SynthesizedStrings)),
NumInputArgStrings(RHS.NumInputArgStrings) {} NumInputArgStrings(RHS.NumInputArgStrings) {}
InputArgList &operator=(InputArgList &&RHS) { InputArgList &operator=(InputArgList &&RHS) {
releaseMemory();
ArgList::operator=(std::move(RHS)); ArgList::operator=(std::move(RHS));
ArgStrings = std::move(RHS.ArgStrings); ArgStrings = std::move(RHS.ArgStrings);
SynthesizedStrings = std::move(RHS.SynthesizedStrings); SynthesizedStrings = std::move(RHS.SynthesizedStrings);
NumInputArgStrings = RHS.NumInputArgStrings; NumInputArgStrings = RHS.NumInputArgStrings;
return *this; return *this;
} }
~InputArgList(); ~InputArgList() { releaseMemory(); }
const char *getArgString(unsigned Index) const override { const char *getArgString(unsigned Index) const override {
return ArgStrings[Index]; return ArgStrings[Index];

View File

@ -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, InputArgList::InputArgList(const char* const *ArgBegin,
const char* const *ArgEnd) const char* const *ArgEnd)
: NumInputArgStrings(ArgEnd - ArgBegin) { : NumInputArgStrings(ArgEnd - ArgBegin) {
ArgStrings.append(ArgBegin, ArgEnd); 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 InputArgList::MakeIndex(StringRef String0) const {
unsigned Index = ArgStrings.size(); unsigned Index = ArgStrings.size();