[lsan] Print direct leaks first.
authorSergey Matveev <earthdok@google.com>
Mon, 22 Jul 2013 11:18:32 +0000 (11:18 +0000)
committerSergey Matveev <earthdok@google.com>
Mon, 22 Jul 2013 11:18:32 +0000 (11:18 +0000)
Direct leaks are higher priority, so it makes sense to have them on top.

llvm-svn: 186819

compiler-rt/lib/lsan/lsan_common.cc

index 8bb89e7..8f57ae0 100644 (file)
@@ -438,8 +438,11 @@ void LeakReport::Add(u32 stack_trace_id, uptr leaked_size, ChunkTag tag) {
   leaks_.push_back(leak);
 }
 
-static bool IsLarger(const Leak &leak1, const Leak &leak2) {
-  return leak1.total_size > leak2.total_size;
+static bool LeakComparator(const Leak &leak1, const Leak &leak2) {
+  if (leak1.is_directly_leaked == leak2.is_directly_leaked)
+    return leak1.total_size > leak2.total_size;
+  else
+    return leak1.is_directly_leaked;
 }
 
 void LeakReport::PrintLargest(uptr num_leaks_to_print) {
@@ -455,7 +458,7 @@ void LeakReport::PrintLargest(uptr num_leaks_to_print) {
     if (!leaks_[i].is_suppressed) unsuppressed_count++;
   if (num_leaks_to_print > 0 && num_leaks_to_print < unsuppressed_count)
     Printf("The %zu largest leak(s):\n", num_leaks_to_print);
-  InternalSort(&leaks_, leaks_.size(), IsLarger);
+  InternalSort(&leaks_, leaks_.size(), LeakComparator);
   uptr leaks_printed = 0;
   for (uptr i = 0; i < leaks_.size(); i++) {
     if (leaks_[i].is_suppressed) continue;