Bug 1395994 - Clone arrays to fix a leak of windows caused by PlacesTransactions keeping references to arrays passed to it. r?mak draft
authorMark Banner <standard8@mozilla.com>
Fri, 01 Sep 2017 16:48:09 +0100
changeset 658613 c48042bcce2341eae74a02ba9da696b2c6054f93
parent 657343 a3585c77e2b1bc5f5fea907e97762f7b47a12033
child 729708 95d7f5937626a6843150fe58c052ed995f6d7de0
push id77826
push userbmo:standard8@mozilla.com
push dateMon, 04 Sep 2017 12:46:12 +0000
reviewersmak
bugs1395994
milestone57.0a1
Bug 1395994 - Clone arrays to fix a leak of windows caused by PlacesTransactions keeping references to arrays passed to it. r?mak MozReview-Commit-ID: CWMyLtmNQuW
toolkit/components/places/PlacesTransactions.jsm
--- a/toolkit/components/places/PlacesTransactions.jsm
+++ b/toolkit/components/places/PlacesTransactions.jsm
@@ -799,19 +799,25 @@ DefineTransaction.defineArrayInputProp =
   this.inputProps.set(name, {
     validateValue(aValue) {
       if (aValue == undefined)
         return [];
 
       if (!Array.isArray(aValue))
         throw new Error(`${name} input property value must be an array`);
 
-      // This also takes care of abandoning the global scope of the input
-      // array (through Array.prototype).
-      return aValue.map(baseProp.validateValue);
+      // We must create a new array in the local scope to avoid a memory leak due
+      // to the array global object. We can't use Cu.cloneInto as that doesn't
+      // handle the URIs. Slice & map also aren't good enough, so we start off
+      // with a clean array and insert what we need into it.
+      let newArray = [];
+      for (let item of aValue) {
+        newArray.push(baseProp.validateValue(item));
+      }
+      return newArray;
     },
 
     // We allow setting either the array property itself (e.g. urls), or a
     // single element of it (url, in that example), that is then transformed
     // into a single-element array.
     validateInput(input, required) {
       if (name in input) {
         // It's not allowed to set both though.