Bug 1036367 - Fix dangerous public destructors in purple/. r=florian
authoraleth <aleth@instantbird.org>
Wed, 09 Jul 2014 20:33:32 +0200
changeset 737 b0681d7c96db64cdbdd931e01ffe43d65a23e0e5
parent 736 719f50c5bf0e0d19e1b5dde9f25dddf46db50c4b
child 738 890a12044644de90709937000071a76dd51442c7
push id17
push useraleth@instantbird.org
push dateWed, 09 Jul 2014 18:34:18 +0000
reviewersflorian
bugs1036367
Bug 1036367 - Fix dangerous public destructors in purple/. r=florian
purplexpcom/src/purpleDNS.h
purplexpcom/src/purpleDebug.h
purplexpcom/src/purpleGListEnumerator.h
purplexpcom/src/purpleGetText.h
purplexpcom/src/purpleInit.cpp
purplexpcom/src/purpleInitAccounts.cpp
purplexpcom/src/purpleSockets.cpp
purplexpcom/src/purpleSockets.h
purplexpcom/src/purpleTimer.cpp
purplexpcom/src/purpleTimer.h
--- a/purplexpcom/src/purpleDNS.h
+++ b/purplexpcom/src/purpleDNS.h
@@ -15,24 +15,24 @@
 #include <nsIDNSListener.h>
 
 class purpleDNSRequest MOZ_FINAL : public nsIDNSListener
 {
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDNSLISTENER
 
   purpleDNSRequest();
-  ~purpleDNSRequest();
   PRUint32 mAccountId;
   PurpleDnsQueryData *query_data;
   PurpleDnsQueryResolvedCallback resolved_cb;
   PurpleDnsQueryFailedCallback failed_cb;
   nsCOMPtr<nsICancelable> asyncResolv;
 
  private:
+  ~purpleDNSRequest();
   inline void Failed(const char *aMsg);
 };
 
 class purpleDNS
 {
  public:
   static void init();
   static void unInit();
--- a/purplexpcom/src/purpleDebug.h
+++ b/purplexpcom/src/purpleDebug.h
@@ -25,16 +25,17 @@ class purpleDebug MOZ_FINAL : public nsI
                                         const char *arg);
 
   static gboolean Enabled(PurpleDebugLevel level,
                           const char *category);
 
  private:
   static nsresult init();
   purpleDebug(); // can only be called by init()
+  ~purpleDebug() {}
   void PrepareFilePath(nsCString &aPath);
   nsresult InitRepositoryInfo();
 
   static purpleDebug *sInstance;
   nsCString mSourceBase;
   nsCString mRepositoryBase;
   PRInt32 mBaseLength;
   PRInt32 mLogLevel;
--- a/purplexpcom/src/purpleGListEnumerator.h
+++ b/purplexpcom/src/purpleGListEnumerator.h
@@ -12,27 +12,27 @@ class purpleGListEnumerator MOZ_FINAL : 
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSISIMPLEENUMERATOR
 
   // Ctor
   purpleGListEnumerator();
 
-  // Dtor
-  ~purpleGListEnumerator();
-
   typedef nsISupports* (*converterCallback) (void *);
   typedef void (*cleanupCallback) (void *);
 
   nsresult Init(GList *aGList, converterCallback aDataToSupports,
                 cleanupCallback aCleanupCallback = NULL,
                 void *aCleanupData = NULL);
 
 private:
+  // Dtor
+  ~purpleGListEnumerator();
+
   void Cleanup();
 
   GList *mGList;
   converterCallback mDataToSupports;
   cleanupCallback mCleanupCallback;
   void *mCleanupData;
 };
 
--- a/purplexpcom/src/purpleGetText.h
+++ b/purplexpcom/src/purpleGetText.h
@@ -27,16 +27,17 @@ class purpleGetText MOZ_FINAL : public n
   struct PluralRule {
     PRUint32 nbForms;
     PluralFormIndexCallback func;
   };
 
  private:
   // can only be called by init();
   purpleGetText();
+  ~purpleGetText() {}
 
   static purpleGetText *sInstance;
 
   struct LangStringCache {
     nsCString packageName;
     nsAutoPtr<nsDataHashtable<nsCStringHashKey, nsTArray<nsCString> *> > table;
   };
 
--- a/purplexpcom/src/purpleInit.cpp
+++ b/purplexpcom/src/purpleInit.cpp
@@ -122,16 +122,17 @@ PurpleGetTextUiOps gettext_uiops = {
 class prefsObserver MOZ_FINAL : public nsIObserver
 {
   public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
     prefsObserver(void *aCallback) : callback(aCallback) {}
 
   private:
+    ~prefsObserver() {}
     gpointer callback;
 };
 
 NS_IMPL_ISUPPORTS(prefsObserver, nsIObserver)
 
 NS_IMETHODIMP prefsObserver::Observe(nsISupports *aSubject,
                                      const char *aTopic,
                                      const char16_t *someData)
--- a/purplexpcom/src/purpleInitAccounts.cpp
+++ b/purplexpcom/src/purpleInitAccounts.cpp
@@ -148,18 +148,18 @@ class purpleAuthorizationRequest MOZ_FIN
 
     purpleAuthorizationRequest(purpleAccount *aAccount,
                                const char *remote_user,
                                PurpleAccountRequestAuthorizationCb authorize_cb,
                                PurpleAccountRequestAuthorizationCb deny_cb,
                                void *user_data);
     void Cancel();
 
-
   private:
+    ~purpleAuthorizationRequest() {}
     nsRefPtr<purpleAccount> mAccount;
     nsCString mRemoteUser;
     PurpleAccountRequestAuthorizationCb mAuthorizeCb, mDenyCb;
     void *mUserData;
 };
 
 NS_IMPL_ISUPPORTS(purpleAuthorizationRequest, prplIBuddyRequest)
 
--- a/purplexpcom/src/purpleSockets.cpp
+++ b/purplexpcom/src/purpleSockets.cpp
@@ -28,16 +28,19 @@ NS_IMPL_ISUPPORTS(purpleSocket, nsIRunna
 PRUint32 purpleSocket::sLastSocket = 0;
 
 
 class purpleSocketNetworkStateObserver MOZ_FINAL : public nsIObserver
 {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
+
+ private:
+  ~purpleSocketNetworkStateObserver() {}
 };
 
 purpleSocket::purpleSocket()
   : mFunction(NULL)
 {
   LOG(("Creating purpleSocket @%x\n", this));
 }
 
--- a/purplexpcom/src/purpleSockets.h
+++ b/purplexpcom/src/purpleSockets.h
@@ -34,48 +34,48 @@ class purpleSocketInternal MOZ_FINAL : p
   nsresult PostEvent();
   nsresult Cancel();
   bool GetCanceled() { return mCanceled; }
 #ifdef PR_LOGGING
   purpleSocketInternal(PRUint32 aId);
 #else
   purpleSocketInternal();
 #endif
-  ~purpleSocketInternal();
 #ifdef PR_LOGGING
   PRUint32 mId;
 #endif
 
  private:
+  ~purpleSocketInternal();
   nsresult OnAttach();
   PRFileDesc *mFd;
   PRInt16 mPollFlagsInternal;
   nsCOMPtr<nsIRunnable> mRunnable;
   bool mAttached;
   bool mDetached;
   bool mCanceled;
 };
 
 class purpleSocket MOZ_FINAL : public nsIRunnable
 {
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   purpleSocket();
-  ~purpleSocket();
 
   nsresult Init(PurpleInputFunction aFunction, gpointer aData, PRInt32 aFd,
                 PurpleInputCondition aCondition, PRInt32 *aResultId);
   void CallLibpurpleCallback();
   void Cancel() { mInternal->Cancel(); }
   PRUint32 GetId() { return mId; }
   PRUint32 GetAccountId() { return mAccountId; }
 
  private:
+  ~purpleSocket();
   static PRUint32 sLastSocket;
   PRUint32 mAccountId;
   PRUint32 mId;
   PRInt32 mFd;
   PurpleInputFunction mFunction;
   gpointer mData;
   PurpleInputCondition mCondition;
   nsRefPtr<purpleSocketInternal> mInternal;
--- a/purplexpcom/src/purpleTimer.cpp
+++ b/purplexpcom/src/purpleTimer.cpp
@@ -17,36 +17,35 @@
 // NSPR_LOG_MODULES=purpleTimer:5
 //
 static PRLogModuleInfo *gPurpleTimerLog = nullptr;
 #endif
 #define LOG(args) PR_LOG(gPurpleTimerLog, PR_LOG_DEBUG, args)
 
 /* Init static members */
 PRUint32 purpleTimer::sLastTimer = 0;
-nsTArray<purpleTimeout *> *purpleTimer::sTimeouts = nullptr;
+nsCOMArray<purpleTimeout> *purpleTimer::sTimeouts = nullptr;
 
 void purpleTimer::init()
 {
 #ifdef PR_LOGGING
   if (!gPurpleTimerLog)
     gPurpleTimerLog = PR_NewLogModule("purpleTimer");
 #endif
-  sTimeouts = new nsTArray<purpleTimeout *>();
+  sTimeouts = new nsCOMArray<purpleTimeout>();
 }
 
 void purpleTimer::unInit()
 {
   LOG(("purpleTimer::unInit: removing %i leftover timeouts",
        sTimeouts->Length()));
 
   for (PRUint32 i = 0; i < sTimeouts->Length(); ++i) {
     purpleTimeout *timeout = (*sTimeouts)[i];
     timeout->mTimer->Cancel();
-    delete timeout;
   }
 
   delete sTimeouts;
   sTimeouts = nullptr;
 }
 
 NS_IMPL_ISUPPORTS(purpleTimeout, nsIRunnable)
 
@@ -139,17 +138,16 @@ gboolean purpleTimer::CancelTimer(PRUint
 {
   NS_ENSURE_TRUE(initialized(), FALSE);
 
   LOG(("Trying to cancel timeout with id %i", aId));
   for (PRUint32 i = 0; i < sTimeouts->Length(); ++i) {
     if ((*sTimeouts)[i]->mId == aId) {
       purpleTimeout *timeout = (*sTimeouts)[i];
       timeout->mTimer->Cancel();
-      delete timeout;
       sTimeouts->RemoveElementAt(i);
       LOG(("Timeout elt found at index %i; canceled and removed", i));
       return TRUE;
     }
   }
 
   LOG(("purpleTimer::CancelTimer : Timeout with id %i not found.", aId));
   return FALSE;
@@ -159,16 +157,15 @@ nsresult purpleTimer::CancelTimerFromAcc
 {
   LOG(("Checking if timers from account %u remain", aAccountId));
   NS_ENSURE_TRUE(initialized(), NS_ERROR_FAILURE);
 
   for (PRInt32 i = sTimeouts->Length() - 1; i >= 0; --i) {
     if ((*sTimeouts)[i]->mAccountId == aAccountId) {
       purpleTimeout *timeout = (*sTimeouts)[i];
       timeout->mTimer->Cancel();
-      delete timeout;
       sTimeouts->RemoveElementAt(i);
       LOG(("Timeout elt found at index %i; canceled and removed", i));
       NS_WARNING("Found timer for disconnected account");
     }
   }
   return NS_OK;
 }
--- a/purplexpcom/src/purpleTimer.h
+++ b/purplexpcom/src/purpleTimer.h
@@ -1,31 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include<nsCOMPtr.h>
-#include "nsTArray.h"
+#include "nsCOMArray.h"
 #include <glib.h>
 #include <nsITimer.h>
 
 #include <nsIRunnable.h>
 class purpleTimeout MOZ_FINAL : public nsIRunnable
 {
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   purpleTimeout() {}
-  ~purpleTimeout() {}
   PRUint32 mAccountId;
   PRUint32 mId;
   nsCOMPtr<nsITimer> mTimer;
   GSourceFunc mFunction;
   gpointer mData;
+
+ private:
+  ~purpleTimeout() {}
 };
 
 class purpleTimer
 {
  public:
   static void init();
   static void unInit();
   static bool initialized() { return !!sTimeouts; }
@@ -33,11 +35,11 @@ class purpleTimer
   static PRUint32 AddTimeout(PRUint32 aInterval,
                              GSourceFunc aFunction,
                              gpointer aData);
   static void ExecTimer(nsITimer *aTimer, void *aTimerClosure);
   static gboolean CancelTimer(PRUint32 aId);
   static nsresult CancelTimerFromAccountId(PRUint32 aAccountId);
 
  private:
-  static nsTArray<purpleTimeout *> *sTimeouts;
+  static nsCOMArray<purpleTimeout> *sTimeouts;
   static PRUint32 sLastTimer;
 };