[network] Avoid accessing raw pointers in nsTransportEventSinkProxy.

This commit is contained in:
Moonchild 2024-06-11 19:01:24 +02:00 • committed by roytam1
commit bcdf7dc845

View file

@ -27,24 +27,22 @@ public:
: mSink(sink) : mSink(sink)
, mTarget(target) , mTarget(target)
, mLock("nsTransportEventSinkProxy.mLock") , mLock("nsTransportEventSinkProxy.mLock")
, mLastEvent(nullptr)
{ {
NS_ADDREF(mSink);
} }
private: private:
virtual ~nsTransportEventSinkProxy() virtual ~nsTransportEventSinkProxy()
{ {
// our reference to mSink could be the last, so be sure to release // our reference to mSink could be the last, so be sure to release
// it on the target thread. otherwise, we could get into trouble. // it on the target thread, otherwise, we could get into trouble.
NS_ProxyRelease(mTarget, dont_AddRef(mSink)); NS_ProxyRelease(mTarget, mSink.forget());
} }
public: public:
nsITransportEventSink *mSink; nsCOMPtr<nsITransportEventSink> mSink;
nsCOMPtr<nsIEventTarget> mTarget; nsCOMPtr<nsIEventTarget> mTarget;
Mutex mLock; Mutex mLock;
nsTransportStatusEvent *mLastEvent; RefPtr<nsTransportStatusEvent> mLastEvent;
}; };
class nsTransportStatusEvent : public Runnable class nsTransportStatusEvent : public Runnable
@ -70,12 +68,14 @@ public:
// if not coalescing all, then last event may not equal self! // if not coalescing all, then last event may not equal self!
{ {
MutexAutoLock lock(mProxy->mLock); MutexAutoLock lock(mProxy->mLock);
if (mProxy->mLastEvent == this) if (mProxy->mLastEvent == this) {
mProxy->mLastEvent = nullptr; mProxy->mLastEvent = nullptr;
}
} }
mProxy->mSink->OnTransportStatus(mTransport, mStatus, mProgress, mProxy->mSink->OnTransportStatus(mTransport, mStatus, mProgress,
mProgressMax); mProgressMax);
mProxy = nullptr;
return NS_OK; return NS_OK;
} }