forked from OSchip/llvm-project
[lsan] malloc_usable_size returns 0 for nullptr
This commit is contained in:
parent
5148c685e3
commit
7788b0c097
|
@ -146,6 +146,8 @@ void GetAllocatorCacheRange(uptr *begin, uptr *end) {
|
|||
}
|
||||
|
||||
uptr GetMallocUsableSize(const void *p) {
|
||||
if (!p)
|
||||
return 0;
|
||||
ChunkMetadata *m = Metadata(p);
|
||||
if (!m) return 0;
|
||||
return m->requested_size;
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// RUN: %clang -O2 %s -o %t && %run %t
|
||||
|
||||
// Ubsan does not provide allocator.
|
||||
// UNSUPPORTED: ubsan
|
||||
|
||||
#include <assert.h>
|
||||
#include <malloc.h>
|
||||
#include <sanitizer/allocator_interface.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
assert(__sanitizer_get_allocated_size(NULL) == 0);
|
||||
assert(malloc_usable_size(NULL) == 0);
|
||||
|
||||
int size = 1234567;
|
||||
void *p = malloc(size);
|
||||
assert(__sanitizer_get_allocated_size(p) == size);
|
||||
assert(malloc_usable_size(p) == size);
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue