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

Unified Diff: third_party/tcmalloc/chromium/src/thread_cache.h

Issue 9528002: Try adding memory corruption check in ThreadCache::Deallocate. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix the memory corruption check. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/thread_cache.h
diff --git a/third_party/tcmalloc/chromium/src/thread_cache.h b/third_party/tcmalloc/chromium/src/thread_cache.h
index d631f45284f9e817d883dcf7df450b7b7c49fe8d..62ab794f9b169b6b86b7f68c31e89d28ab3971c2 100644
--- a/third_party/tcmalloc/chromium/src/thread_cache.h
+++ b/third_party/tcmalloc/chromium/src/thread_cache.h
@@ -214,6 +214,12 @@ class ThreadCache {
return FL_Pop(&list_);
}
+ void* Next() {
+ if (list_ == NULL)
+ return NULL;
+ return FL_Next(list_);
+ }
+
void PushRange(int N, void *start, void *end) {
FL_PushRange(&list_, start, end);
length_ += N;
@@ -366,6 +372,12 @@ inline void ThreadCache::Deallocate(void* ptr, size_t cl) {
FreeList* list = &list_[cl];
size_ += Static::sizemap()->ByteSizeForClass(cl);
ssize_t size_headroom = max_size_ - size_ - 1;
+
+ // This catches back-to-back frees of allocs in the same size
+ // class. A more comprehensive (and expensive) test would be to walk
+ // the entire freelist. But this might be enough to find some bugs.
+ ASSERT(ptr != list->Next());
+
list->Push(ptr);
ssize_t list_headroom =
static_cast<ssize_t>(list->max_length()) - list->length();

Powered by Google App Engine
This is Rietveld 408576698