Bug 954452 - Avoid shutdown crash when some JS code holds a reference to a purpleAccountBuddy instance after libpurple is uninitialized.
authorFlorian Quèze <florian@instantbird.org>
Mon, 16 Jan 2012 23:37:24 +0100
changeset 18518 6eff20a4f25d314c0edca61277bfb6c167c6703b
parent 18517 5c6c9d5a540b5c07d438b8e155d3d77c11d8a60e
child 18519 2f998822f3aad6793c97ba2e6b1306f5d7dab091
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)
bugs954452
Bug 954452 - Avoid shutdown crash when some JS code holds a reference to a purpleAccountBuddy instance after libpurple is uninitialized.
chat/components/public/imIContactsService.idl
chat/components/src/imContacts.js
chat/modules/jsProtoHelper.jsm
--- a/chat/components/public/imIContactsService.idl
+++ b/chat/components/public/imIContactsService.idl
@@ -256,9 +256,14 @@ interface imIAccountBuddy: imIStatusInfo
   // server-stored buddy list.
            attribute imITag tag;
   readonly attribute AUTF8String userName;
   readonly attribute AUTF8String normalizedName;
            attribute AUTF8String serverAlias;
 
   // remove the buddy from the buddy list of this account.
   void remove();
+
+  // Called by the contacts service during its uninitialization to
+  // notify that all references kept to imIBuddy or imIAccount
+  // instances should be released now.
+  void unInit();
 };
--- a/chat/components/src/imContacts.js
+++ b/chat/components/src/imContacts.js
@@ -909,16 +909,18 @@ function Buddy(aId, aKey, aName, aSrvAli
 
   this._contact._buddies.push(this);
 
   BuddiesById[this._id] = this;
 }
 Buddy.prototype = {
   get id() this._id,
   destroy: function() {
+    for each (let ab in this._accounts)
+      ab.unInit();
     delete this._accounts;
     delete this._observers;
     delete this._preferredAccount;
   },
   get protocol() this._accounts[0].account.protocol,
   get userName() this._name,
   get normalizedName() this._key,
   _srvAlias: "",
--- a/chat/modules/jsProtoHelper.jsm
+++ b/chat/modules/jsProtoHelper.jsm
@@ -222,16 +222,21 @@ const GenericAccountBuddyPrototype = {
     this._buddy = aBuddy;
     if (aBuddy) {
       let displayName = aBuddy.displayName;
       if (displayName != aUserName)
         this._serverAlias = displayName;
     }
     this._userName = aUserName;
   },
+  unInit: function() {
+    delete this._tag;
+    delete this._account;
+    delete this._buddy;
+  },
 
   get account() this._account.imAccount,
   set buddy(aBuddy) {
     if (this._buddy)
       throw Cr.NS_ERROR_ALREADY_INITIALIZED;
     this._buddy = aBuddy;
   },
   get buddy() this._buddy,