Hi, 
How does allocator_may_return_null=1 work? 

When I run the following code with address sanitizer compile option, it 
gave me some error (see below for detail). After I use 
allocator_may_return_null=1 
in ASAN_OPTIONS, the error still there. 
int main()
 {
   // test bad alloc exception
     try{
                   void* ladd = new char[999999999999];
                   if (ladd == 0)
                           printf("return null pointer\n");
           }
           catch(...)
           {
                   printf("expection throw\n");
        }
 return 0;
}
 
compiler option:
g++ -g -std=c++11 -lpthread -fsanitize=address -fno-omit-frame-pointer 
foo.cpp -o foo

ASAN_OPTIONS=symbolize=1

bash-4.1$ ./foo
==9485==AddressSanitizer's allocator is terminating the process instead of 
returning 0
==9485==*If you don't like this behavior set allocator_may_return_null=1*
==9485==AddressSanitizer CHECK failed: 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator.cc:216 "((0)) 
!= (0)" (0x0, 0x0)
    #0 0x7fd80c924475 in AsanCheckFailed 
../../../../libsanitizer/asan/asan_rtl.cc:67
    #1 0x7fd80c93ecd9 in __sanitizer::CheckFailed(char const*, int, char 
const*, unsigned long long, unsigned long long) 
../../../../libsanitizer/sanitizer_common/sanitizer_termination.cc:77
    #2 0x7fd80c929526 in __sanitizer::ReportAllocatorCannotReturnNull() 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator.cc:216
    #3 0x7fd80c92958a in __sanitizer::ReturnNullOrDieOnFailure::OnOOM() 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator.cc:239
    #4 0x7fd80c85a501 in 
__sanitizer::LargeMmapAllocator<__asan::AsanMapUnmapCallback, 
__sanitizer::ReturnNullOrDieOnFailure>::Allocate(__sanitizer::AllocatorStats*, 
unsigned long, unsigned long) 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator_secondary.h:44
    #5 0x7fd80c85a501 in 
__sanitizer::CombinedAllocator<__sanitizer::SizeClassAllocator64<__asan::AP64>, 
__sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator64<__asan::AP64>
 
>, __sanitizer::LargeMmapAllocator<__asan::AsanMapUnmapCallback, 
__sanitizer::ReturnNullOrDieOnFailure> 
>::Allocate(__sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator64<__asan::AP64>
> 
>*, unsigned long, unsigned long) 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator_combined.h:62
    #6 0x7fd80c85a501 in __asan::Allocator::Allocate(unsigned long, 
unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType, bool) 
../../../../libsanitizer/asan/asan_allocator.cc:422
    #7 0x7fd80c857e07 in __asan::asan_memalign(unsigned long, unsigned 
long, __sanitizer::BufferedStackTrace*, __asan::AllocType) 
../../../../libsanitizer/asan/asan_allocator.cc:856
    #8 0x7fd80c91b35f in operator new[](unsigned long) 
../../../../libsanitizer/asan/asan_new_delete.cc:93
    #9 0x400aab in main /home/xfan/issue/linux_gas/foo.cpp:26
    #10 0x35f561ed1c in __libc_start_main (/lib64/libc.so.6+0x35f561ed1c)
    #11 0x400958  (/home/xfan/issue/linux_gas/foo+0x400958)

ASAN_OPTIONS=symbolize=1:*allocator_may_return_null=1*
bash-4.1$ ./foo
==9431==AddressSanitizer's allocator is terminating the process instead of 
returning 0
==9431==*If you don't like this behavior set allocator_may_return_null=1*
==9431==AddressSanitizer CHECK failed: 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator.cc:216 "((0)) 
!= (0)" (0x0, 0x0)
    #0 0x7fc4c10e8475 in AsanCheckFailed 
../../../../libsanitizer/asan/asan_rtl.cc:67
    #1 0x7fc4c1102cd9 in __sanitizer::CheckFailed(char const*, int, char 
const*, unsigned long long, unsigned long long) 
../../../../libsanitizer/sanitizer_common/sanitizer_termination.cc:77
    #2 0x7fc4c10ed526 in __sanitizer::ReportAllocatorCannotReturnNull() 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator.cc:216
    #3 0x7fc4c10ed5af in __sanitizer::DieOnFailure::OnOOM() 
../../../../libsanitizer/sanitizer_common/sanitizer_allocator.cc:248
    #4 0x7fc4c10df4a4 in operator new[](unsigned long) 
../../../../libsanitizer/asan/asan_new_delete.cc:93
    #5 0x400aab in main /home/xfan/issue/linux_gas/foo.cpp:26
    #6 0x35f561ed1c in __libc_start_main (/lib64/libc.so.6+0x35f561ed1c)
    #7 0x400958  (/home/xfan/issue/linux_gas/foo+0x400958)

I am using GCC 8.2, Red hat Linux.
Thanks,
Xingyan

-- 
You received this message because you are subscribed to the Google Groups 
"address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to address-sanitizer+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to