1 // Check that malloc_default_zone and malloc_zone_from_ptr return the
2 // sanitizer-installed malloc zone even when MallocStackLogging (MSL) is
3 // requested. This prevents crashes in certain situations. Note that the
4 // sanitizers and MSL cannot be used together. If both are enabled, MSL
5 // functionality is essentially deactivated since it only hooks the default
6 // allocator which is replaced by a custom sanitizer allocator.
8 // MSL=lite creates its own special malloc zone, copies the passed zone name,
10 // RUN: echo "leak:create_and_insert_msl_lite_zone" >> lsan.supp
12 // RUN: %clangxx -g %s -o %t
13 // RUN: %run %t | FileCheck %s
14 // RUN: %env MallocStackLogging=lite LSAN_OPTIONS=suppressions=lsan.supp %run %t | FileCheck %s
15 // RUN: %env MallocStackLogging=full %run %t | FileCheck %s
17 // UBSan does not install a malloc zone.
21 #include <malloc/malloc.h>
26 malloc_zone_t
*default_zone
= malloc_default_zone();
27 printf("default zone name: %s\n", malloc_get_zone_name(default_zone
));
28 // CHECK: default zone name: {{a|l|t}}san
30 void *ptr1
= malloc(10);
31 void *ptr2
= malloc_zone_malloc(default_zone
, 10);
33 malloc_zone_t
* zone1
= malloc_zone_from_ptr(ptr1
);
34 malloc_zone_t
* zone2
= malloc_zone_from_ptr(ptr2
);
36 printf("zone1: %d\n", zone1
== default_zone
);
37 printf("zone2: %d\n", zone2
== default_zone
);
42 malloc_zone_free(zone2
, ptr2
);