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

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: fix windows build 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
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/memory_linux.cc
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
index 6bed68bd8320346b1ff98a39417e604e0339b020..bb4c91e0b2dc9a3610b8b4c39ae675e558623057 100644
--- a/base/process/memory_linux.cc
+++ b/base/process/memory_linux.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/process/internal_linux.h"
#include "base/strings/string_number_conversions.h"
+#include "third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h"
willchan no longer on Chromium 2013/11/28 03:38:28 You should use an #if defined(USE_TCMALLOC) here.
namespace base {
@@ -125,6 +126,35 @@ int posix_memalign(void** ptr, size_t alignment, size_t size) {
#endif // !*_SANITIZER
+bool UncheckedMalloc(size_t size, void** result) {
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+ defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
+ (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
+ *result = malloc(size);
+#elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
+ *result = __libc_malloc(size);
+#else // tcmalloc
willchan no longer on Chromium 2013/11/28 03:38:28 please do #elif defined(USE_TCMALLOC) and an #else
+ *result = tc_malloc_skip_new_handler(size);
+#endif
+ return *result;
+}
+
+bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
+ const size_t alloc_size = num_items * size;
+
+ // Overflow check
+ if (size && ((alloc_size / size) != num_items)) {
+ result = NULL;
+ return false;
+ }
+
+ if (!UncheckedMalloc(alloc_size, result))
+ return false;
+
+ memset(result, 0, alloc_size);
+ return true;
+}
+
void EnableTerminationOnHeapCorruption() {
// On Linux, there nothing to do AFAIK.
}
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698