[llvm-commits] [compiler-rt] r158885 - in /compiler-rt/trunk/lib/asan: asan_internal.h asan_malloc_mac.cc asan_rtl.cc
Alexander Potapenko
glider at google.com
Wed Jun 20 18:01:21 PDT 2012
Author: glider
Date: Wed Jun 20 20:01:20 2012
New Revision: 158885
URL: http://llvm.org/viewvc/llvm-project?rev=158885&view=rev
Log:
Factor the common code out of cf_free and mz_free.
Introduce the mac_ignore_invalid_free flag (0 by default) which makes both cf_free and mz_free ignore invalid free invocations and leak memory.
Modified:
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
compiler-rt/trunk/lib/asan/asan_rtl.cc
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=158885&r1=158884&r2=158885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Wed Jun 20 20:01:20 2012
@@ -148,6 +148,7 @@
extern bool FLAG_replace_str;
extern bool FLAG_replace_intrin;
extern bool FLAG_replace_cfallocator;
+extern bool FLAG_mac_ignore_invalid_free;
extern bool FLAG_fast_unwind;
extern bool FLAG_use_fake_stack;
extern uptr FLAG_max_malloc_fill_size;
Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=158885&r1=158884&r2=158885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Wed Jun 20 20:01:20 2012
@@ -149,8 +149,7 @@
}
}
-// TODO(glider): the allocation callbacks need to be refactored.
-void mz_free(malloc_zone_t *zone, void *ptr) {
+void ALWAYS_INLINE free_common(void *context, void *ptr) {
if (!ptr) return;
malloc_zone_t *orig_zone = malloc_zone_from_ptr(ptr);
// For some reason Chromium calls mz_free() for pointers that belong to
@@ -160,12 +159,12 @@
system_purgeable_zone->free(system_purgeable_zone, ptr);
return;
}
- if (asan_mz_size(ptr)) {
+ if (!FLAG_mac_ignore_invalid_free || asan_mz_size(ptr)) {
GET_STACK_TRACE_HERE_FOR_FREE(ptr);
asan_free(ptr, &stack);
} else {
// Let us just leak this memory for now.
- AsanPrintf("mz_free(%p) -- attempting to free unallocated memory.\n"
+ AsanPrintf("free_common(%p) -- attempting to free unallocated memory.\n"
"AddressSanitizer is ignoring this error on Mac OS now.\n",
ptr);
print_zone_for_ptr(ptr);
@@ -175,29 +174,13 @@
}
}
+// TODO(glider): the allocation callbacks need to be refactored.
+void mz_free(malloc_zone_t *zone, void *ptr) {
+ free_common(zone, ptr);
+}
+
void cf_free(void *ptr, void *info) {
- if (!ptr) return;
- malloc_zone_t *orig_zone = malloc_zone_from_ptr(ptr);
- // For some reason Chromium calls mz_free() for pointers that belong to
- // DefaultPurgeableMallocZone instead of asan_zone. We might want to
- // fix this someday.
- if (orig_zone == system_purgeable_zone) {
- system_purgeable_zone->free(system_purgeable_zone, ptr);
- return;
- }
- if (asan_mz_size(ptr)) {
- GET_STACK_TRACE_HERE_FOR_FREE(ptr);
- asan_free(ptr, &stack);
- } else {
- // Let us just leak this memory for now.
- AsanPrintf("cf_free(%p) -- attempting to free unallocated memory.\n"
- "AddressSanitizer is ignoring this error on Mac OS now.\n",
- ptr);
- print_zone_for_ptr(ptr);
- GET_STACK_TRACE_HERE_FOR_FREE(ptr);
- stack.PrintStack();
- return;
- }
+ free_common(info, ptr);
}
void *mz_realloc(malloc_zone_t *zone, void *ptr, size_t size) {
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=158885&r1=158884&r2=158885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed Jun 20 20:01:20 2012
@@ -73,6 +73,7 @@
s64 FLAG_demangle = 1;
s64 FLAG_debug = 0;
bool FLAG_replace_cfallocator = 1; // Used on Mac only.
+bool FLAG_mac_ignore_invalid_free = 0; // Used on Mac only.
bool FLAG_replace_str = 1;
bool FLAG_replace_intrin = 1;
bool FLAG_use_fake_stack = 1;
@@ -458,6 +459,7 @@
IntFlagValue(options, "demangle=", &FLAG_demangle);
IntFlagValue(options, "debug=", &FLAG_debug);
BoolFlagValue(options, "replace_cfallocator=", &FLAG_replace_cfallocator);
+ BoolFlagValue(options, "mac_ignore_invalid_free=", &FLAG_mac_ignore_invalid_free);
BoolFlagValue(options, "replace_str=", &FLAG_replace_str);
BoolFlagValue(options, "replace_intrin=", &FLAG_replace_intrin);
BoolFlagValue(options, "use_fake_stack=", &FLAG_use_fake_stack);
More information about the llvm-commits
mailing list