[Option] Plug a leak when move-assigning an InputArgList.
[oota-llvm.git] / include / llvm / Option / ArgList.h
index e29cf24661a6cc83990971efb5e381f91ff33331..ef4005761b75cebd67829443282acfcc10460c65 100644 (file)
@@ -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];