Bug 702517 - Fix memory leak in GfxInfoCollector and add new DefineProperty overload. r=jrmuizel
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 18 Nov 2011 17:00:38 +1300
changeset 80414 e789d1408f877c736d4a8a8bc0ec5024be5cfa78
parent 80413 fce30603aea9b6618e333f8e28760318414b4a87
child 80415 c83fc47b1433b5ef801505b3d0a7abcdf46f8ec3
push id3443
push usermwoodrow@mozilla.com
push dateFri, 18 Nov 2011 04:01:12 +0000
treeherdermozilla-inbound@4af4c72eafa7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs702517
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 702517 - Fix memory leak in GfxInfoCollector and add new DefineProperty overload. r=jrmuizel
widget/src/xpwidgets/GfxInfoBase.cpp
widget/src/xpwidgets/GfxInfoCollector.h
--- a/widget/src/xpwidgets/GfxInfoBase.cpp
+++ b/widget/src/xpwidgets/GfxInfoBase.cpp
@@ -907,16 +907,20 @@ GfxInfoBase::RemoveCollector(GfxInfoColl
 {
   InitCollectors();
   for (PRUint32 i = 0; i < sCollectors->Length(); i++) {
     if ((*sCollectors)[i] == collector) {
       sCollectors->RemoveElementAt(i);
       break;
     }
   }
+  if (sCollectors->IsEmpty()) {
+    delete sCollectors;
+    sCollectors = nsnull;
+  }
 }
 
 GfxInfoCollectorBase::GfxInfoCollectorBase()
 {
   GfxInfoBase::AddCollector(this);
 }
 
 GfxInfoCollectorBase::~GfxInfoCollectorBase()
--- a/widget/src/xpwidgets/GfxInfoCollector.h
+++ b/widget/src/xpwidgets/GfxInfoCollector.h
@@ -72,16 +72,22 @@ class InfoObject
       mOk = JS_FALSE;
 
     if (!mOk)
       return;
 
     mOk = JS_DefineProperty(mCx, mObj, name, STRING_TO_JSVAL(string), NULL, NULL, JSPROP_ENUMERATE);
   }
 
+  void DefineProperty(const char *name, const char *value)
+  { 
+    nsAutoString string = NS_ConvertASCIItoUTF16(value);
+    DefineProperty(name, string); 
+  }
+
   private:
   // We need to ensure that this object lives on the stack so that GC sees it properly
   InfoObject(JSContext *aCx) : mCx(aCx), mOk(JS_TRUE)
   {
     mObj = JS_NewObject(mCx, NULL, NULL, NULL);
     if (!mObj)
       mOk = JS_FALSE;
   }