[compiler-rt] r233257 - [Sanitizer] Plug a leak in POSIXSymbolizer::FindModuleForAddress

Timur Iskhodzhanov timurrrr at google.com
Thu Mar 26 00:14:29 PDT 2015


Author: timurrrr
Date: Thu Mar 26 02:14:29 2015
New Revision: 233257

URL: http://llvm.org/viewvc/llvm-project?rev=233257&view=rev
Log:
[Sanitizer] Plug a leak in POSIXSymbolizer::FindModuleForAddress

It was happening when we looked up a PC for a module that was dlopen'ed/dlclose'd
after the last time we fetched the list of modules

Reviewed at http://reviews.llvm.org/D8618

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=233257&r1=233256&r2=233257&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Thu Mar 26 02:14:29 2015
@@ -548,6 +548,7 @@ uptr InternalBinarySearch(const Containe
 // executable or a shared object).
 class LoadedModule {
  public:
+  LoadedModule() : full_name_(nullptr), base_address_(0) {}
   LoadedModule(const char *module_name, uptr base_address);
   void clear();
   void addAddressRange(uptr beg, uptr end, bool executable);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc?rev=233257&r1=233256&r2=233257&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc Thu Mar 26 02:14:29 2015
@@ -352,7 +352,7 @@ class InternalSymbolizer : public Symbol
 class POSIXSymbolizer : public Symbolizer {
  public:
   explicit POSIXSymbolizer(IntrusiveList<SymbolizerTool> tools)
-      : Symbolizer(tools) {}
+      : Symbolizer(tools), n_modules_(0), modules_fresh_(false) {}
 
  private:
   const char *PlatformDemangle(const char *name) override {
@@ -368,10 +368,9 @@ class POSIXSymbolizer : public Symbolize
 
   LoadedModule *FindModuleForAddress(uptr address) {
     bool modules_were_reloaded = false;
-    if (modules_ == 0 || !modules_fresh_) {
-      modules_ = (LoadedModule*)(symbolizer_allocator_.Allocate(
-          kMaxNumberOfModuleContexts * sizeof(LoadedModule)));
-      CHECK(modules_);
+    if (!modules_fresh_) {
+      for (uptr i = 0; i < n_modules_; i++)
+        modules_[i].clear();
       n_modules_ = GetListOfModules(modules_, kMaxNumberOfModuleContexts,
                                     /* filter */ 0);
       CHECK_GT(n_modules_, 0);
@@ -408,7 +407,7 @@ class POSIXSymbolizer : public Symbolize
 
   // 16K loaded modules should be enough for everyone.
   static const uptr kMaxNumberOfModuleContexts = 1 << 14;
-  LoadedModule *modules_;  // Array of module descriptions is leaked.
+  LoadedModule modules_[kMaxNumberOfModuleContexts];
   uptr n_modules_;
   // If stale, need to reload the modules before looking up addresses.
   bool modules_fresh_;





More information about the llvm-commits mailing list