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

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: 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 f81429b2ac0d7ed72eeeb3d2c4d7882ff6428744..2810604fbfc8500d7f48d24b24119de3b622e05e 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"
namespace base {
@@ -123,6 +124,33 @@ 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
+ *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 (alloc_size && (alloc_size / size) != num_items)
willchan no longer on Chromium 2013/11/12 16:04:19 Please add another set of parentheses around the !
kbalazs 2013/11/12 18:40:46 I made a mistake, the first part of the condition
+ return NULL;
willchan no longer on Chromium 2013/11/12 16:04:19 Shouldn't this be 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