[lld] r263677 - Use allocator in YAML code to avoid leaking atom content.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 18:04:02 PDT 2016


Thanks for taking a look.  Yeah, there’s a few more.

I’ve committed a bunch more in http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/11159 which is running now.  That should hopefully fix most of MappingTraits cases.

The remainder i’ve seen are cases where we have a std::vector inside an Atom.  The memory allocated in the vector is never freed because we never run the destructor.  For the YAML parser this is fine as I can just move the data from the vector to an allocator once parsing is done.  For the CompactUnwindPass, i’ll need to see how big the data gets and whether moving it is feasible.

Cheers
Pete
> On Mar 16, 2016, at 5:46 PM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
> 
> Thanks!
> 
> Unfortunately looks like there are more:
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/11158/steps/check-lld%20asan/logs/stdio
> 
> Looks like more places where an allocator needs to be passed to yaml.
> 
> Cheers,
> Rafael
> 
> 
> On 16 March 2016 at 16:30, Pete Cooper via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> Author: pete
>> Date: Wed Mar 16 18:30:27 2016
>> New Revision: 263677
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=263677&view=rev
>> Log:
>> Use allocator in YAML code to avoid leaking atom content.
>> 
>> In lld we allocate atoms on an allocator and so don't run their
>> destructors.  This means we also shouldn't allocate memory inside
>> them without that also being on an allocator.
>> 
>> Reviewed by Lang Hames and Rafael Espindola.
>> 
>> Modified:
>>    lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
>> 
>> Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=263677&r1=263676&r2=263677&view=diff
>> ==============================================================================
>> --- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
>> +++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Wed Mar 16 18:30:27 2016
>> @@ -745,8 +745,9 @@ template <> struct MappingTraits<const l
>>   };
>> 
>>   static void mapping(IO &io, const lld::Reference *&ref) {
>> +    YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext());
>>     MappingNormalizationHeap<NormalizedReference, const lld::Reference *> keys(
>> -        io, ref);
>> +        io, ref, &info->_file->allocator());
>> 
>>     io.mapRequired("kind",   keys->_mappedKind);
>>     io.mapOptional("offset", keys->_offset);
>> @@ -889,12 +890,12 @@ template <> struct MappingTraits<const l
>>   };
>> 
>>   static void mapping(IO &io, const lld::DefinedAtom *&atom) {
>> +    YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext());
>>     MappingNormalizationHeap<NormalizedAtom, const lld::DefinedAtom *> keys(
>> -        io, atom);
>> +        io, atom, &info->_file->allocator());
>>     if (io.outputting()) {
>>       // If writing YAML, check if atom needs a ref-name.
>>       typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile;
>> -      YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext());
>>       assert(info != nullptr);
>>       NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file);
>>       assert(f);
>> @@ -979,8 +980,9 @@ template <> struct MappingTraits<const l
>>   };
>> 
>>   static void mapping(IO &io, const lld::UndefinedAtom *&atom) {
>> +    YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext());
>>     MappingNormalizationHeap<NormalizedAtom, const lld::UndefinedAtom *> keys(
>> -        io, atom);
>> +        io, atom, &info->_file->allocator());
>> 
>>     io.mapRequired("name",        keys->_name);
>>     io.mapOptional("can-be-null", keys->_canBeNull,
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list