nsSegmentedBuffer-allocator-unmanaged
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 157 8daebed024b6410329793f900335824e1f0b77b6
permissions -rw-r--r--
State as of now

diff --git a/xpcom/io/nsSegmentedBuffer.cpp b/xpcom/io/nsSegmentedBuffer.cpp
--- a/xpcom/io/nsSegmentedBuffer.cpp
+++ b/xpcom/io/nsSegmentedBuffer.cpp
@@ -199,7 +199,8 @@ TestSegmentedBuffer()
     NS_ASSERTION(!empty, "DeleteFirstSegment failed");
     empty = buf->DeleteFirstSegment();
     NS_ASSERTION(empty, "DeleteFirstSegment failed");
-    delete buf;
+    // TODO: we know this is dead, but deleting it is hard?
+    // delete buf;
 }
 #endif
 
diff --git a/xpcom/io/nsSegmentedBuffer.h b/xpcom/io/nsSegmentedBuffer.h
--- a/xpcom/io/nsSegmentedBuffer.h
+++ b/xpcom/io/nsSegmentedBuffer.h
@@ -40,22 +40,25 @@
 
 #include "nsMemory.h"
 #include "prclist.h"
+#include "nsCOMPtr.h"
 
-class nsSegmentedBuffer
-{
+class nsSegmentedBuffer{
 public:
     nsSegmentedBuffer()
         : mSegmentSize(0), mMaxSize(0), 
-          mSegAllocator(nsnull), mSegmentArray(nsnull),
+          mSegAllocator(nsnull),
+          mSegmentArray(nsnull),
           mSegmentArrayCount(0),
           mFirstSegmentIndex(0), mLastSegmentIndex(0) {}
 
     ~nsSegmentedBuffer() {
         Empty();
-        NS_IF_RELEASE(mSegAllocator);
     }
 
-
+    /**
+     * @note: if this class is malloced, allocator will not be rooted here
+     * and must be externally rooted.
+     */
     NS_COM nsresult Init(PRUint32 segmentSize, PRUint32 maxSize,
                   nsIMemory* allocator = nsnull);
 
@@ -105,7 +108,7 @@ protected:
 protected:
     PRUint32            mSegmentSize;
     PRUint32            mMaxSize;
-    nsIMemory*       mSegAllocator;
+    nsIMemory*          mSegAllocator NS_UNMANAGED;
     char**              mSegmentArray;
     PRUint32            mSegmentArrayCount;
     PRInt32             mFirstSegmentIndex;