From 93c15cc9467b0bd9e9201edbda75204681dd23da Mon Sep 17 00:00:00 2001 From: Ray Kraesig Date: Tue, 16 Jul 2024 22:09:38 +0000 Subject: [PATCH] Bug 1598915 - [1/2] Drive-by cleanup: replace manual pointer-fiddling with RefPtr r=win-reviewers,handyman `nsDataObj::mTransferable`'s lifecycle and ownership semantics are trivially that of `RefPtr`. Use it. (We do not presently extend this to `m_enumFE`, below; according to comments in IEnumFE.h, that one's less trivial.) No functional changes. Differential Revision: https://phabricator.services.mozilla.com/D216624 --- widget/windows/nsDataObj.cpp | 13 ++----------- widget/windows/nsDataObj.h | 5 ++--- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/widget/windows/nsDataObj.cpp b/widget/windows/nsDataObj.cpp index 60e2784f378b..ead7bae51280 100644 --- a/widget/windows/nsDataObj.cpp +++ b/widget/windows/nsDataObj.cpp @@ -530,7 +530,7 @@ nsDataObj::nsDataObj(nsIURI* uri) // destruction //----------------------------------------------------- nsDataObj::~nsDataObj() { - NS_IF_RELEASE(mTransferable); + mTransferable = nullptr; mDataFlavors.Clear(); @@ -774,7 +774,7 @@ STDMETHODIMP nsDataObj::GetData(LPFORMATETC aFormat, LPSTGMEDIUM pSTM) { // ("***** nsDataObj::GetData - Unknown format %u\n", format)); return GetText(df, *aFormat, *pSTM); } // switch - } // if + } // if dfInx++; } // while @@ -1861,16 +1861,7 @@ void nsDataObj::AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE) { // Sets the transferable object //----------------------------------------------------- void nsDataObj::SetTransferable(nsITransferable* aTransferable) { - NS_IF_RELEASE(mTransferable); - mTransferable = aTransferable; - if (nullptr == mTransferable) { - return; - } - - NS_ADDREF(mTransferable); - - return; } // diff --git a/widget/windows/nsDataObj.h b/widget/windows/nsDataObj.h index 17683e371a16..6c8f1a45ac45 100644 --- a/widget/windows/nsDataObj.h +++ b/widget/windows/nsDataObj.h @@ -166,9 +166,8 @@ class nsDataObj : public IDataObject, public IDataObjectAsyncCapability { private: nsTArray mDataFlavors; - nsITransferable* mTransferable; // nsDataObj owns and ref counts - // nsITransferable, the nsITransferable does - // know anything about the nsDataObj + // the nsITransferable knows nothing about the nsDataObj + RefPtr mTransferable; protected: CEnumFormatEtc* m_enumFE; // Ownership Rules: