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

Side by Side Diff: third_party/tcmalloc/chromium/src/tcmalloc.cc

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes inspired by trybots Created 6 years, 9 months 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 unified diff | Download patch
« no previous file with comments | « third_party/tcmalloc/chromium/src/debugallocation.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 #ifdef HAVE_STRUCT_MALLINFO 1712 #ifdef HAVE_STRUCT_MALLINFO
1713 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { 1713 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW {
1714 return do_mallinfo(); 1714 return do_mallinfo();
1715 } 1715 }
1716 #endif 1716 #endif
1717 1717
1718 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { 1718 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW {
1719 return MallocExtension::instance()->GetAllocatedSize(ptr); 1719 return MallocExtension::instance()->GetAllocatedSize(ptr);
1720 } 1720 }
1721 1721
1722 #if defined(OS_LINUX)
1723 extern "C" void* PERFTOOLS_DLL_DECL tc_malloc_skip_new_handler(size_t size) {
1724 void* result = do_malloc(size);
1725 MallocHook::InvokeNewHook(result, size);
1726 return result;
1727 }
1728 #endif
1729
1722 #endif // TCMALLOC_USING_DEBUGALLOCATION 1730 #endif // TCMALLOC_USING_DEBUGALLOCATION
1723 1731
1732 #if defined(OS_LINUX)
1733 // Alias the weak symbol in chromium to our implementation.
1734 extern "C" __attribute__((visibility("default"), alias("tc_malloc_skip_new_handl er")))
1735 void* tc_malloc_skip_new_handler_weak(size_t size);
1736 #endif
1737
1724 // --- Validation implementation with an extra mark ---------------------------- 1738 // --- Validation implementation with an extra mark ----------------------------
1725 // We will put a mark at the extreme end of each allocation block. We make 1739 // We will put a mark at the extreme end of each allocation block. We make
1726 // sure that we always allocate enough "extra memory" that we can fit in the 1740 // sure that we always allocate enough "extra memory" that we can fit in the
1727 // mark, and still provide the requested usable region. If ever that mark is 1741 // mark, and still provide the requested usable region. If ever that mark is
1728 // not as expected, then we know that the user is corrupting memory beyond their 1742 // not as expected, then we know that the user is corrupting memory beyond their
1729 // request size, or that they have called free a second time without having 1743 // request size, or that they have called free a second time without having
1730 // the memory allocated (again). This allows us to spot most double free()s, 1744 // the memory allocated (again). This allows us to spot most double free()s,
1731 // but some can "slip by" or confuse our logic if the caller reallocates memory 1745 // but some can "slip by" or confuse our logic if the caller reallocates memory
1732 // (for a second use) before performing an evil double-free of a first 1746 // (for a second use) before performing an evil double-free of a first
1733 // allocation 1747 // allocation
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 *mark = ~allocated_mark; // Distinctively not allocated. 1885 *mark = ~allocated_mark; // Distinctively not allocated.
1872 } 1886 }
1873 1887
1874 static void MarkAllocatedRegion(void* ptr) { 1888 static void MarkAllocatedRegion(void* ptr) {
1875 if (ptr == NULL) return; 1889 if (ptr == NULL) return;
1876 MarkType* mark = GetMarkLocation(ptr); 1890 MarkType* mark = GetMarkLocation(ptr);
1877 *mark = GetMarkValue(ptr, mark); 1891 *mark = GetMarkValue(ptr, mark);
1878 } 1892 }
1879 1893
1880 #endif // TCMALLOC_VALIDATION 1894 #endif // TCMALLOC_VALIDATION
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/debugallocation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698