Avoid crash caused by 033dfcf2e107.
authorFlorian Quèze <florian@instantbird.org>
Fri, 23 Dec 2011 17:08:51 +0100
changeset 18506 f5acee57fa79bbf087d64bbde5786bd8b6ff9cae
parent 18505 db8bc10c718b8d9877593d3d25da2dcdf1566348
child 18507 bfeb1dc9931fb191be262c23c68ae1070435d4a7
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Avoid crash caused by 033dfcf2e107.
chat/protocols/xmpp/xmpp-xml.jsm
--- a/chat/protocols/xmpp/xmpp-xml.jsm
+++ b/chat/protocols/xmpp/xmpp-xml.jsm
@@ -321,37 +321,49 @@ function XMPPParser(aListener) {
                  .createInstance(Ci.nsISAXXMLReader);
   this._parser.contentHandler = this;
   this._parser.errorHandler = this;
   this._parser.parseAsync(null);
   this._listener = aListener;
   this._parser.onStartRequest(this._dummyRequest, null);
 }
 XMPPParser.prototype = {
+  _destroyPending: false,
   destroy: function() {
     // Avoid reference cycles
     this._parser.contentHandler = null;
     delete this._listener;
+    // Calling onStopRequest while we are in an onDataAvailable
+    // callback crashes, don't do it.
+    if (this._inOnDataAvailable) {
+      this._destroyPending = true;
+      return;
+    }
     this._parser.onStopRequest(this._dummyRequest, null, Cr.NS_OK);
     // Stopping the request causes parse errors (because we parsed
     // only partial XML documents?), so the error handler is still
     // needed to avoid the errors being reported to the error console.
     this._parser.errorHandler = null;
     delete this._parser;
   },
   _dummyRequest: {
     cancel: function() { },
     isPending: function() { },
     resume: function() { },
     suspend: function() { }
   },
 
+  _inOnDataAvailable: false,
   onDataAvailable: function(aInputStream, aOffset, aCount) {
+    this._inOnDataAvailable = true;
     this._parser.onDataAvailable(this._dummyRequest, null,
                                  aInputStream, aOffset, aCount);
+    delete this._inOnDataAvailable;
+    if (this._destroyPending)
+      this.destroy();
   },
 
   /* nsISAXContentHandler implementation */
   startDocument: function() { },
   endDocument: function() { },
 
   startElement: function(aUri, aLocalName, aQName, aAttributes) {
     if (aQName == "stream:stream") {