<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 23, 2015 at 8:28 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Tue Jun 23 10:28:10 2015<br>
New Revision: 240417<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D240417-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=qcioVOybvQJP2q144Nb3HQ70nyXuMf58IN0_8g9hBHY&s=IbslWyuqRvJyPcAERPvi2Gxgsa9jAJhIckPRY0vEUVw&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=240417&view=rev</a><br>
Log:<br>
[Option] Plug a leak when move-assigning an InputArgList.<br>
<br>
The class has a non-trivial dtor so we have to clean up before we move<br>
in new members. Remove misleading comment as a default move assignment<br>
operator will never be synthesized for this class.<br></blockquote><div><br></div><div>Thanks for the fix!<br><br>(& now extra incentive (I wouldn't say extra motivated... ) to pull the container out of ArgList into the derived classes so that it doesn't have that conditional ownership & can just use raw pointers in DerivedArgList and unique_ptrs in InputArgList)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/include/llvm/Option/ArgList.h<br>
    llvm/trunk/lib/Option/ArgList.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Option/ArgList.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_include_llvm_Option_ArgList.h-3Frev-3D240417-26r1-3D240416-26r2-3D240417-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=qcioVOybvQJP2q144Nb3HQ70nyXuMf58IN0_8g9hBHY&s=2UEEoum9NyTs3uVAwugjNuqim9kz49ZYZ45NzLYb220&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Option/ArgList.h?rev=240417&r1=240416&r2=240417&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Option/ArgList.h (original)<br>
+++ llvm/trunk/include/llvm/Option/ArgList.h Tue Jun 23 10:28:10 2015<br>
@@ -325,22 +325,24 @@ private:<br>
   /// The number of original input argument strings.<br>
   unsigned NumInputArgStrings;<br>
<br>
+  /// Release allocated arguments.<br>
+  void releaseMemory();<br>
+<br>
 public:<br>
   InputArgList(const char* const *ArgBegin, const char* const *ArgEnd);<br>
-  // Default move operations implemented for the convenience of MSVC. Nothing<br>
-  // special here.<br>
   InputArgList(InputArgList &&RHS)<br>
       : ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)),<br>
         SynthesizedStrings(std::move(RHS.SynthesizedStrings)),<br>
         NumInputArgStrings(RHS.NumInputArgStrings) {}<br>
   InputArgList &operator=(InputArgList &&RHS) {<br>
+    releaseMemory();<br>
     ArgList::operator=(std::move(RHS));<br>
     ArgStrings = std::move(RHS.ArgStrings);<br>
     SynthesizedStrings = std::move(RHS.SynthesizedStrings);<br>
     NumInputArgStrings = RHS.NumInputArgStrings;<br>
     return *this;<br>
   }<br>
-  ~InputArgList();<br>
+  ~InputArgList() { releaseMemory(); }<br>
<br>
   const char *getArgString(unsigned Index) const override {<br>
     return ArgStrings[Index];<br>
<br>
Modified: llvm/trunk/lib/Option/ArgList.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Option_ArgList.cpp-3Frev-3D240417-26r1-3D240416-26r2-3D240417-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=qcioVOybvQJP2q144Nb3HQ70nyXuMf58IN0_8g9hBHY&s=y3LWWXCUNR4eOkryCUdWA6f8waY4WtJQwV7qWAvBUbo&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/ArgList.cpp?rev=240417&r1=240416&r2=240417&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Option/ArgList.cpp (original)<br>
+++ llvm/trunk/lib/Option/ArgList.cpp Tue Jun 23 10:28:10 2015<br>
@@ -315,18 +315,18 @@ const char *ArgList::GetOrMakeJoinedArgS<br>
<br>
 //<br>
<br>
+void InputArgList::releaseMemory() {<br>
+  // An InputArgList always owns its arguments.<br>
+  for (Arg *A : *this)<br>
+    delete A;<br>
+}<br>
+<br>
 InputArgList::InputArgList(const char* const *ArgBegin,<br>
                            const char* const *ArgEnd)<br>
   : NumInputArgStrings(ArgEnd - ArgBegin) {<br>
   ArgStrings.append(ArgBegin, ArgEnd);<br>
 }<br>
<br>
-InputArgList::~InputArgList() {<br>
-  // An InputArgList always owns its arguments.<br>
-  for (iterator it = begin(), ie = end(); it != ie; ++it)<br>
-    delete *it;<br>
-}<br>
-<br>
 unsigned InputArgList::MakeIndex(StringRef String0) const {<br>
   unsigned Index = ArgStrings.size();<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>