Bug 1494238 - Fix nsMsgIMAPFolderACL::GetOtherUsers() (missing addref) by replacing class AdoptUTF8StringEnumerator with using NS_NewAdoptingUTF8StringEnumerator(). r=aceman
authorJorg K <jorgk@jorgk.com>
Thu, 27 Sep 2018 10:27:37 +0200
changeset 33243 102bf0b97b0ab0cab19a71ca61d11fe35639d354
parent 33242 aa44e834870fc2310c0e3b19811e4f3c70bff036
child 33244 5b5a269c9cdee41f53623588c233331665495cfc
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersaceman
bugs1494238
Bug 1494238 - Fix nsMsgIMAPFolderACL::GetOtherUsers() (missing addref) by replacing class AdoptUTF8StringEnumerator with using NS_NewAdoptingUTF8StringEnumerator(). r=aceman
mailnews/imap/src/nsImapMailFolder.cpp
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -6325,68 +6325,25 @@ bool nsMsgIMAPFolderACL::SetFolderRights
 }
 
 NS_IMETHODIMP nsImapMailFolder::GetOtherUsersWithAccess(
         nsIUTF8StringEnumerator** aResult)
 {
   return GetFolderACL()->GetOtherUsers(aResult);
 }
 
-class AdoptUTF8StringEnumerator final : public nsStringEnumeratorBase
-{
-public:
-  explicit AdoptUTF8StringEnumerator(nsTArray<nsCString>* array) :
-    mStrings(array), mIndex(0)
-  {}
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIUTF8STRINGENUMERATOR
-
-  using nsStringEnumeratorBase::GetNext;
-
-private:
-  ~AdoptUTF8StringEnumerator()
-  {
-    delete mStrings;
-  }
-
-  nsTArray<nsCString>* mStrings;
-  uint32_t             mIndex;
-};
-
-NS_IMPL_ISUPPORTS(AdoptUTF8StringEnumerator, nsIUTF8StringEnumerator, nsIStringEnumerator)
-
-NS_IMETHODIMP
-AdoptUTF8StringEnumerator::HasMore(bool *aResult)
-{
-  *aResult = mIndex < mStrings->Length();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-AdoptUTF8StringEnumerator::GetNext(nsACString& aResult)
-{
-  if (mIndex >= mStrings->Length())
-    return NS_ERROR_UNEXPECTED;
-
-  aResult.Assign((*mStrings)[mIndex]);
-  ++mIndex;
-  return NS_OK;
-}
-
 nsresult nsMsgIMAPFolderACL::GetOtherUsers(nsIUTF8StringEnumerator** aResult)
 {
   nsTArray<nsCString>* resultArray = new nsTArray<nsCString>;
   for (auto iter = m_rightsHash.Iter(); !iter.Done(); iter.Next()) {
     resultArray->AppendElement(iter.Key());
   }
 
   // enumerator will free resultArray
-  *aResult = new AdoptUTF8StringEnumerator(resultArray);
-  return NS_OK;
+  return NS_NewAdoptingUTF8StringEnumerator(aResult, resultArray);
 }
 
 nsresult nsImapMailFolder::GetPermissionsForUser(const nsACString& otherUser,
         nsACString& aResult)
 {
   nsCString str;
   nsresult rv = GetFolderACL()->GetRightsStringForUser(otherUser, str);
   NS_ENSURE_SUCCESS(rv, rv);