From ec4a5165515ef94d0bc1c1b164c52d48aaede4b2 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Wed, 9 Nov 2011 20:40:09 -0500 Subject: [PATCH] Bug 701210 - nsTArray::SizeOf() should use malloc_usable_size. r=roc --- xpcom/glue/nsTArray.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 83d8a232639..c4212c9a8bd 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -442,6 +442,7 @@ public: typedef nsTArray_SafeElementAtHelper safeelementat_helper_type; using safeelementat_helper_type::SafeElementAt; + using base_type::EmptyHdr; // A special value that is used to indicate an invalid or unknown index // into the array. @@ -515,10 +516,13 @@ public: } // @return The amount of memory taken used by this nsTArray, not including - // sizeof(this) + // sizeof(*this). size_t SizeOf() const { - return this->UsesAutoArrayBuffer() ? - 0 : this->Capacity() * sizeof(elem_type) + sizeof(*this->Hdr()); + if (this->UsesAutoArrayBuffer() || Hdr() == EmptyHdr()) + return 0; + size_t usable = moz_malloc_usable_size(this->Hdr()); + return usable ? usable : + this->Capacity() * sizeof(elem_type) + sizeof(*this->Hdr()); } //