Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(945)

Unified Diff: base/process/memory_linux.cc

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make possible to check memory allocations inside chromium Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/process/memory_linux.cc
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
index f81429b2ac0d7ed72eeeb3d2c4d7882ff6428744..01b7614e79b2e2ede4f6de57758586ee462dd0e7 100644
--- a/base/process/memory_linux.cc
+++ b/base/process/memory_linux.cc
@@ -115,6 +115,10 @@ int posix_memalign(void** ptr, size_t alignment, size_t size) {
} // extern C
+void* UncheckedMalloc(size_t size) {
+ return __libc_malloc(size);
+}
+
#else
// TODO(mostynb@opera.com): dlsym dance
@@ -123,6 +127,29 @@ int posix_memalign(void** ptr, size_t alignment, size_t size) {
#endif // !*_SANITIZER
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+ defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
+ (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
+
+void* UncheckedMalloc(size_t size) {
+ return malloc(size);
+}
+
+#endif
+
+void* UncheckedCalloc(size_t num_items, size_t size) {
+ const size_t alloc_size = num_items * size;
+
+ // Overflow check
+ if (alloc_size && (alloc_size / size) != num_items)
+ return NULL;
+
+ void* result = UncheckedMalloc(alloc_size);
+ if (result)
+ memset(result, 0, alloc_size);
+ return result;
+}
+
void EnableTerminationOnHeapCorruption() {
// On Linux, there nothing to do AFAIK.
}
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_win.cc » ('j') | base/process/memory_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698