Index: lib/asan/asan_errors.h =================================================================== --- lib/asan/asan_errors.h +++ lib/asan/asan_errors.h @@ -163,13 +163,31 @@ void Print(); }; +struct ErrorMallocUsableSizeNotOwned : ErrorBase { + u32 tid; + // ErrorMallocUsableSizeNotOwned doesn't own the stack trace. + BufferedStackTrace *stack; + AddressDescriptionBase addr_description; + // VS2013 doesn't implement unrestricted unions, so we need a trivial default + // constructor + ErrorMallocUsableSizeNotOwned() = default; + ErrorMallocUsableSizeNotOwned(uptr addr, u32 tid_, BufferedStackTrace *stack_) + : tid(tid_), stack(stack_) { + addr_description = + AddressDescription(addr, /*shouldLockThreadRegistry=*/false); + scariness.Clear(); + } + void Print(); +}; + #define FOR_EACH_ERROR_KIND_MEMBER_NAME_PAIR(macro) \ macro(StackOverflow, stack_overflow) \ macro(DeadlySignal, deadly_signal) \ macro(DoubleFree, double_free) \ macro(NewDeleteSizeMismatch, new_delete_size_mismatch) \ macro(FreeNotMalloced, free_not_malloced) \ - macro(AllocTypeMismatch, alloc_type_mismatch) + macro(AllocTypeMismatch, alloc_type_mismatch) \ + macro(MallocUsableSizeNotOwned, malloc_uzable_size_not_owned) enum ErrorKind { kErrorKindInvalid = 0, Index: lib/asan/asan_errors.cc =================================================================== --- lib/asan/asan_errors.cc +++ lib/asan/asan_errors.cc @@ -164,4 +164,17 @@ "ASAN_OPTIONS=alloc_dealloc_mismatch=0\n"); } +void ErrorMallocUsableSizeNotOwned::Print() { + Decorator d; + Printf("%s", d.Warning()); + Report( + "ERROR: AddressSanitizer: attempting to call malloc_usable_size() for " + "pointer which is not owned: %p\n", + addr_description.Address()); + Printf("%s", d.EndWarning()); + stack->Print(); + addr_description.Print(); + ReportErrorSummary("bad-malloc_usable_size", stack); +} + } // namespace __asan Index: lib/asan/asan_report.cc =================================================================== --- lib/asan/asan_report.cc +++ lib/asan/asan_report.cc @@ -365,15 +365,8 @@ void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack) { ScopedInErrorReport in_report; - Decorator d; - Printf("%s", d.Warning()); - Report("ERROR: AddressSanitizer: attempting to call " - "malloc_usable_size() for pointer which is " - "not owned: %p\n", addr); - Printf("%s", d.EndWarning()); - stack->Print(); - DescribeAddressIfHeap(addr); - ReportErrorSummary("bad-malloc_usable_size", stack); + ErrorMallocUsableSizeNotOwned error(addr, GetCurrentTidOrInvalid(), stack); + in_report.ReportError(error); } void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,