Bug 802823 - Early cleanup of message listeners in ActivityProxy.js [r=gwagner]
authorFabrice Desré <fabrice@mozilla.com>
Thu, 18 Oct 2012 15:30:57 -0700
changeset 110849 1167feab3ae545d1f006525c9fbc8bbabc1677f5
parent 110848 62627192e1563789da8b97907ffd342f4348f31d
child 110850 47a36175f4a5d47f91a7319536537c6e382e783b
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersgwagner
bugs802823
milestone19.0a1
Bug 802823 - Early cleanup of message listeners in ActivityProxy.js [r=gwagner]
dom/activities/src/ActivityProxy.js
--- a/dom/activities/src/ActivityProxy.js
+++ b/dom/activities/src/ActivityProxy.js
@@ -75,21 +75,26 @@ ActivityProxy.prototype = {
         Services.DOMRequest.fireSuccess(this.activity,
                                         ObjectWrapper.wrap(msg.result, this.window));
         break;
       case "Activity:FireError":
         debug("FireError");
         Services.DOMRequest.fireError(this.activity, msg.error);
         break;
     }
+    // We can only get one FireSuccess / FireError message, so cleanup as soon as possible.
+    this.cleanup();
   },
 
   cleanup: function actProxy_cleanup() {
     debug("cleanup");
-    cpmm.removeMessageListener("Activity:FireSuccess", this);
-    cpmm.removeMessageListener("Activity:FireError", this);
+    if (!this.cleanedUp) {
+      cpmm.removeMessageListener("Activity:FireSuccess", this);
+      cpmm.removeMessageListener("Activity:FireError", this);
+    }
+    this.cleanedUp = true;
   },
 
   classID: Components.ID("{ba9bd5cb-76a0-4ecf-a7b3-d2f7c43c5949}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIActivityProxy])
 }
 
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityProxy]);