r207031 - Fix leak introduced in r194610, found by LSan.

Nico Weber thakis at chromium.org
Thu Apr 24 09:52:12 PDT 2014


On Thu, Apr 24, 2014 at 1:02 AM, Dmitri Gribenko <gribozavr at gmail.com>wrote:

> On Wed, Apr 23, 2014 at 10:58 PM, Dmitri Gribenko <gribozavr at gmail.com>
> wrote:
> > On Wed, Apr 23, 2014 at 10:54 PM, Nico Weber <thakis at chromium.org>
> wrote:
> >> On Wed, Apr 23, 2014 at 2:53 PM, Richard Smith <richard at metafoo.co.uk>
> >> wrote:
> >>>
> >>> On Wed, Apr 23, 2014 at 2:41 PM, Nico Weber <nicolasweber at gmx.de>
> wrote:
> >>>>
> >>>> Author: nico
> >>>> Date: Wed Apr 23 16:41:51 2014
> >>>> New Revision: 207031
> >>>>
> >>>> URL: http://llvm.org/viewvc/llvm-project?rev=207031&view=rev
> >>>> Log:
> >>>> Fix leak introduced in r194610, found by LSan.
> >>>>
> >>>> LSan folks: LSan pointed to
> >>>>     #0 0x4953e0 in operator new[](unsigned long)
> >>>> llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:64
> >>>>     #1 0x7fb82af5372f in clang::RewriteRope::MakeRopeString(char
> const*,
> >>>> char const*) llvm/tools/clang/lib/Rewrite/Core/RewriteRope.cpp:796
> >>>> instead of to the actual leak, which made tracking this down slower
> than
> >>>> it could have been.
> >>>>
> >>>> Modified:
> >>>>     cfe/trunk/include/clang/Index/CommentToXML.h
> >>>>     cfe/trunk/lib/Index/CommentToXML.cpp
> >>>>
> >>>> Modified: cfe/trunk/include/clang/Index/CommentToXML.h
> >>>> URL:
> >>>>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/CommentToXML.h?rev=207031&r1=207030&r2=207031&view=diff
> >>>>
> >>>>
> ==============================================================================
> >>>> --- cfe/trunk/include/clang/Index/CommentToXML.h (original)
> >>>> +++ cfe/trunk/include/clang/Index/CommentToXML.h Wed Apr 23 16:41:51
> 2014
> >>>> @@ -29,6 +29,7 @@ class CommentToXMLConverter {
> >>>>
> >>>>  public:
> >>>>    CommentToXMLConverter() : FormatContext(0),
> FormatInMemoryUniqueId(0)
> >>>> {}
> >>>> +  ~CommentToXMLConverter();
> >>>>
> >>>>    void convertCommentToHTML(const comments::FullComment *FC,
> >>>>                              SmallVectorImpl<char> &HTML,
> >>>>
> >>>> Modified: cfe/trunk/lib/Index/CommentToXML.cpp
> >>>> URL:
> >>>>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/CommentToXML.cpp?rev=207031&r1=207030&r2=207031&view=diff
> >>>>
> >>>>
> ==============================================================================
> >>>> --- cfe/trunk/lib/Index/CommentToXML.cpp (original)
> >>>> +++ cfe/trunk/lib/Index/CommentToXML.cpp Wed Apr 23 16:41:51 2014
> >>>> @@ -1136,6 +1136,10 @@ void CommentASTToXMLConverter::appendToR
> >>>>    Result << "]]>";
> >>>>  }
> >>>>
> >>>> +CommentToXMLConverter::~CommentToXMLConverter() {
> >>>> +  delete FormatContext;
> >>>
> >>>
> >>> Is it possible to use unique_ptr here?
> >>
> >>
> >> That was my first attempt, but unique_ptr requires a complete type and
> >> SimpleFormatContext is defined in lib/Index while CommentToXML.h is in
> >> include/clang/Index. Is it possible to use unique_ptr in this scenario?
> >
> > The destructor can be put out-of line into .cpp and defaulted.
>
> r207087.
>

Ah, so one can use unique_ptr with forward-declared classes when
constructors and destructors are out of line, thanks :-)

(Looks like msvs doesn't like defaulting though; thanks to chapuni for
fixing that!)


>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140424/5a83bd56/attachment.html>


More information about the cfe-commits mailing list