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

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: weak symbol 2 Created 6 years, 10 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
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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 #endif // TCMALLOC_USING_DEBUGALLOCATION 1722 #endif // TCMALLOC_USING_DEBUGALLOCATION
1723 1723
1724 // Define the strong symbol that overrides tc_malloc_skip_new_handler_weak
1725 // in chromium.
1726 #if defined(OS_LINUX)
1727 extern "C" __attribute__((alias ("tc_malloc_skip_new_handler")))
1728 void* tc_malloc_skip_new_handler_weak(size_t size);
1729
1730 extern "C" void* tc_malloc_skip_new_handler(size_t size) {
1731 void* result = do_malloc(size);
1732 MallocHook::InvokeNewHook(result, size);
1733 return result;
1734 }
1735 #endif
1736
1724 // --- Validation implementation with an extra mark ---------------------------- 1737 // --- Validation implementation with an extra mark ----------------------------
1725 // We will put a mark at the extreme end of each allocation block. We make 1738 // 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 1739 // 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 1740 // 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 1741 // 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 1742 // 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, 1743 // 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 1744 // 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 1745 // (for a second use) before performing an evil double-free of a first
1733 // allocation 1746 // allocation
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 *mark = ~allocated_mark; // Distinctively not allocated. 1884 *mark = ~allocated_mark; // Distinctively not allocated.
1872 } 1885 }
1873 1886
1874 static void MarkAllocatedRegion(void* ptr) { 1887 static void MarkAllocatedRegion(void* ptr) {
1875 if (ptr == NULL) return; 1888 if (ptr == NULL) return;
1876 MarkType* mark = GetMarkLocation(ptr); 1889 MarkType* mark = GetMarkLocation(ptr);
1877 *mark = GetMarkValue(ptr, mark); 1890 *mark = GetMarkValue(ptr, mark);
1878 } 1891 }
1879 1892
1880 #endif // TCMALLOC_VALIDATION 1893 #endif // TCMALLOC_VALIDATION
OLDNEW
« base/process/memory_win.cc ('K') | « third_party/tcmalloc/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698