diff --git a/string/obsolete/nsStr.h b/string/obsolete/nsStr.h index 8757ce92f85..0802f394325 100644 --- a/string/obsolete/nsStr.h +++ b/string/obsolete/nsStr.h @@ -43,6 +43,7 @@ #define _nsStr #include "nscore.h" +#include "nsCppSharedAllocator.h" //---------------------------------------------------------------------------------------- @@ -311,7 +312,11 @@ public: aDest.mCapacity=theNewCapacity++; size_t theSize=(theNewCapacity< shared_allocator; + aDest.mStr = shared_allocator.allocate(theSize); + aDest.mOwnsBuffer=1; return PR_TRUE; } @@ -319,7 +324,9 @@ public: virtual PRBool Free(nsStr& aDest){ if(aDest.mStr){ if(aDest.mOwnsBuffer){ - delete [] aDest.mStr; + // delete [] aDest.mStr; + nsCppSharedAllocator shared_allocator; + shared_allocator.deallocate(aDest.mStr, aDest.mCapacity); } aDest.mStr=0; aDest.mOwnsBuffer=0; diff --git a/xpcom/ds/nsCRT.cpp b/xpcom/ds/nsCRT.cpp index 1dad15e3b19..1149cc905d8 100644 --- a/xpcom/ds/nsCRT.cpp +++ b/xpcom/ds/nsCRT.cpp @@ -485,7 +485,12 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n) PRUnichar* nsCRT::strdup(const PRUnichar* str) { PRUint32 len = nsCRT::strlen(str) + 1; // add one for null - PRUnichar* rslt = new PRUnichar[len]; + + + nsCppSharedAllocator shared_allocator; + PRUnichar* rslt = shared_allocator.allocate(len); + // PRUnichar* rslt = new PRUnichar[len]; + if (rslt == NULL) return NULL; nsCRT::memcpy(rslt, str, len * sizeof(PRUnichar)); return rslt; diff --git a/xpcom/ds/nsCRT.h b/xpcom/ds/nsCRT.h index c44a5665f83..3dc6b4e510b 100644 --- a/xpcom/ds/nsCRT.h +++ b/xpcom/ds/nsCRT.h @@ -23,6 +23,7 @@ #include "plstr.h" #include "nscore.h" #include "prtypes.h" +#include "nsCppSharedAllocator.h" #define CR '\015' #define LF '\012' @@ -201,7 +202,8 @@ public: static PRUnichar* strdup(const PRUnichar* str); static void free(PRUnichar* str) { - delete[] str; + nsCppSharedAllocator shared_allocator; + shared_allocator.deallocate(str, 0 /*we never new or kept the size*/); } /// Compute a hashcode for a C string diff --git a/xpcom/ds/nsStr.h b/xpcom/ds/nsStr.h index 8757ce92f85..0802f394325 100644 --- a/xpcom/ds/nsStr.h +++ b/xpcom/ds/nsStr.h @@ -43,6 +43,7 @@ #define _nsStr #include "nscore.h" +#include "nsCppSharedAllocator.h" //---------------------------------------------------------------------------------------- @@ -311,7 +312,11 @@ public: aDest.mCapacity=theNewCapacity++; size_t theSize=(theNewCapacity< shared_allocator; + aDest.mStr = shared_allocator.allocate(theSize); + aDest.mOwnsBuffer=1; return PR_TRUE; } @@ -319,7 +324,9 @@ public: virtual PRBool Free(nsStr& aDest){ if(aDest.mStr){ if(aDest.mOwnsBuffer){ - delete [] aDest.mStr; + // delete [] aDest.mStr; + nsCppSharedAllocator shared_allocator; + shared_allocator.deallocate(aDest.mStr, aDest.mCapacity); } aDest.mStr=0; aDest.mOwnsBuffer=0; diff --git a/xpcom/string/obsolete/nsStr.h b/xpcom/string/obsolete/nsStr.h index 8757ce92f85..0802f394325 100644 --- a/xpcom/string/obsolete/nsStr.h +++ b/xpcom/string/obsolete/nsStr.h @@ -43,6 +43,7 @@ #define _nsStr #include "nscore.h" +#include "nsCppSharedAllocator.h" //---------------------------------------------------------------------------------------- @@ -311,7 +312,11 @@ public: aDest.mCapacity=theNewCapacity++; size_t theSize=(theNewCapacity< shared_allocator; + aDest.mStr = shared_allocator.allocate(theSize); + aDest.mOwnsBuffer=1; return PR_TRUE; } @@ -319,7 +324,9 @@ public: virtual PRBool Free(nsStr& aDest){ if(aDest.mStr){ if(aDest.mOwnsBuffer){ - delete [] aDest.mStr; + // delete [] aDest.mStr; + nsCppSharedAllocator shared_allocator; + shared_allocator.deallocate(aDest.mStr, aDest.mCapacity); } aDest.mStr=0; aDest.mOwnsBuffer=0;