Skip to content

Commit

Permalink
Bug 1164581 - Adding an overload for NS_ProxyRelease that accepts alr…
Browse files Browse the repository at this point in the history
…eady_AddRefed, and removing all the others. r=bobbyholley

--HG--
extra : rebase_source : 3c6bba6613a14e48239d302bdd0f7fe2e322265d
  • Loading branch information
aidin36 committed Feb 7, 2016
1 parent 8fa85e0 commit 69cf7e0
Show file tree
Hide file tree
Showing 53 changed files with 151 additions and 453 deletions.
12 changes: 1 addition & 11 deletions dom/archivereader/ArchiveEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,7 @@ ArchiveReaderEvent::ArchiveReaderEvent(ArchiveReader* aArchiveReader)
ArchiveReaderEvent::~ArchiveReaderEvent()
{
if (!NS_IsMainThread()) {
nsIMIMEService* mimeService;
mMimeService.forget(&mimeService);

if (mimeService) {
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
NS_WARN_IF_FALSE(mainThread, "Couldn't get the main thread! Leaking!");

if (mainThread) {
NS_ProxyRelease(mainThread, mimeService);
}
}
NS_ReleaseOnMainThread(mMimeService.forget());
}

MOZ_COUNT_DTOR(ArchiveReaderEvent);
Expand Down
4 changes: 2 additions & 2 deletions dom/base/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,11 @@ Console::~Console()

if (!NS_IsMainThread()) {
if (mStorage) {
NS_ReleaseOnMainThread(mStorage);
NS_ReleaseOnMainThread(mStorage.forget());
}

if (mSandbox) {
NS_ReleaseOnMainThread(mSandbox);
NS_ReleaseOnMainThread(mSandbox.forget());
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ WebSocketImpl::Disconnect()
// until the end of the method.
RefPtr<WebSocketImpl> kungfuDeathGrip = this;

NS_ReleaseOnMainThread(mChannel);
NS_ReleaseOnMainThread(static_cast<nsIWebSocketEventService*>(mService.forget().take()));
NS_ReleaseOnMainThread(mChannel.forget());
NS_ReleaseOnMainThread(mService.forget());

mWebSocket->DontKeepAliveAnyMore();
mWebSocket->mImpl = nullptr;
Expand Down
13 changes: 2 additions & 11 deletions dom/base/nsScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,17 +782,8 @@ nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest)
NotifyOffThreadScriptLoadCompletedRunnable::~NotifyOffThreadScriptLoadCompletedRunnable()
{
if (MOZ_UNLIKELY(mRequest || mLoader) && !NS_IsMainThread()) {
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
if (mainThread) {
NS_ProxyRelease(mainThread, mRequest);
NS_ProxyRelease(mainThread, mLoader);
} else {
MOZ_ASSERT(false, "We really shouldn't leak!");
// Better to leak than crash.
Unused << mRequest.forget();
Unused << mLoader.forget();
}
NS_ReleaseOnMainThread(mRequest.forget());
NS_ReleaseOnMainThread(mLoader.forget());
}
}
Expand Down
5 changes: 1 addition & 4 deletions dom/cache/ManagerId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ ManagerId::~ManagerId()

// The PBackground worker thread shouldn't be running after the main thread
// is stopped. So main thread is guaranteed to exist here.
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
MOZ_ASSERT(mainThread);

NS_ProxyRelease(mainThread, mPrincipal.forget().take());
NS_ReleaseOnMainThread(mPrincipal.forget());
}

} // namespace cache
Expand Down
2 changes: 1 addition & 1 deletion dom/devicestorage/DeviceStorageStatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ DeviceStorageStatics::ListenerWrapper::ListenerWrapper(nsDOMDeviceStorage* aList
DeviceStorageStatics::ListenerWrapper::~ListenerWrapper()
{
// Even weak pointers are not thread safe
NS_ProxyRelease(mOwningThread, mListener);
NS_ProxyRelease(mOwningThread, mListener.forget());
}

bool
Expand Down
3 changes: 1 addition & 2 deletions dom/devicestorage/nsDeviceStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3716,8 +3716,7 @@ DeviceStorageRequestManager::~DeviceStorageRequestManager()
while (i > 0) {
--i;
DS_LOG_ERROR("terminate %u", mPending[i].mId);
NS_ProxyRelease(mOwningThread,
NS_ISUPPORTS_CAST(EventTarget*, mPending[i].mRequest.forget().take()));
NS_ProxyRelease(mOwningThread, mPending[i].mRequest.forget());
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions dom/media/webspeech/recognition/SpeechStreamListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ SpeechStreamListener::~SpeechStreamListener()
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));

SpeechRecognition* forgottenRecognition = nullptr;
mRecognition.swap(forgottenRecognition);
NS_ProxyRelease(mainThread,
static_cast<DOMEventTargetHelper*>(forgottenRecognition));
NS_ProxyRelease(mainThread, mRecognition.forget());
}

void
Expand Down
17 changes: 2 additions & 15 deletions dom/workers/WorkerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3626,17 +3626,8 @@ WorkerDebugger::~WorkerDebugger()
MOZ_ASSERT(!mWorkerPrivate);

if (!NS_IsMainThread()) {
nsCOMPtr<nsIThread> mainThread;
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))) {
NS_WARNING("Failed to proxy release of listeners, leaking instead!");
}

for (size_t index = 0; index < mListeners.Length(); ++index) {
nsIWorkerDebuggerListener* listener = nullptr;
mListeners[index].forget(&listener);
if (NS_FAILED(NS_ProxyRelease(mainThread, listener))) {
NS_WARNING("Failed to proxy release of listener, leaking instead!");
}
NS_ReleaseOnMainThread(mListeners[index].forget());
}
}
}
Expand Down Expand Up @@ -4158,11 +4149,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
}

if (parentStatus > Running) {
nsCOMPtr<nsIThread> mainThread;
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread))) ||
NS_FAILED(NS_ProxyRelease(mainThread, loadInfo.mChannel))) {
NS_WARNING("Failed to proxy release of channel, leaking instead!");
}
NS_ReleaseOnMainThread(loadInfo.mChannel.forget());
return NS_ERROR_FAILURE;
}

Expand Down
11 changes: 2 additions & 9 deletions extensions/gio/nsGIOProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,10 @@ nsGIOInputStream::Close()
mDirListPtr = nullptr;
}

if (mChannel)
{
nsresult rv = NS_OK;

nsCOMPtr<nsIThread> thread = do_GetMainThread();
if (thread)
rv = NS_ProxyRelease(thread, mChannel);
if (mChannel) {
NS_ReleaseOnMainThread(dont_AddRef(mChannel));

NS_ASSERTION(thread && NS_SUCCEEDED(rv), "leaking channel reference");
mChannel = nullptr;
(void) rv;
}

mSpec.Truncate(); // free memory
Expand Down
23 changes: 3 additions & 20 deletions extensions/spellcheck/src/mozPersonalDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ class mozPersonalDictionaryLoader final : public nsRunnable
mDict->SyncLoad();

// Release the dictionary on the main thread
mozPersonalDictionary *dict;
mDict.forget(&dict);

nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
if (mainThread) {
NS_ProxyRelease(mainThread, static_cast<mozIPersonalDictionary *>(dict));
} else {
// It's better to leak the dictionary than to release it on a wrong thread
NS_WARNING("Cannot get main thread, leaking mozPersonalDictionary.");
}
NS_ReleaseOnMainThread(mDict.forget());

return NS_OK;
}
Expand Down Expand Up @@ -145,16 +136,8 @@ class mozPersonalDictionarySave final : public nsRunnable
}

// Release the dictionary on the main thread.
mozPersonalDictionary *dict;
mDict.forget(&dict);

nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
if (mainThread) {
NS_ProxyRelease(mainThread, static_cast<mozIPersonalDictionary *>(dict));
} else {
// It's better to leak the dictionary than to release it on a wrong thread.
NS_WARNING("Cannot get main thread, leaking mozPersonalDictionary.");
}
NS_ReleaseOnMainThread(mDict.forget());

return NS_OK;
}

Expand Down
11 changes: 1 addition & 10 deletions image/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,7 @@ Decoder::~Decoder()
if (mImage && !NS_IsMainThread()) {
// Dispatch mImage to main thread to prevent it from being destructed by the
// decode thread.
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
NS_WARN_IF_FALSE(mainThread, "Couldn't get the main thread!");
if (mainThread) {
// Handle ambiguous nsISupports inheritance.
RasterImage* rawImg = nullptr;
mImage.swap(rawImg);
DebugOnly<nsresult> rv =
NS_ProxyRelease(mainThread, NS_ISUPPORTS_CAST(ImageResource*, rawImg));
MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed to proxy release to main thread");
}
NS_ReleaseOnMainThread(mImage.forget());
}
}

Expand Down
7 changes: 1 addition & 6 deletions image/decoders/icon/mac/nsIconChannelCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
nsIconChannel::~nsIconChannel()
{
if (mLoadInfo) {
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));

nsILoadInfo* forgetableLoadInfo;
mLoadInfo.forget(&forgetableLoadInfo);
NS_ProxyRelease(mainThread, forgetableLoadInfo, false);
NS_ReleaseOnMainThread(mLoadInfo.forget());
}
}

Expand Down
7 changes: 1 addition & 6 deletions image/decoders/icon/win/nsIconChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ nsIconChannel::nsIconChannel()
nsIconChannel::~nsIconChannel()
{
if (mLoadInfo) {
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));

nsILoadInfo* forgetableLoadInfo;
mLoadInfo.forget(&forgetableLoadInfo);
NS_ProxyRelease(mainThread, forgetableLoadInfo, false);
NS_ReleaseOnMainThread(mLoadInfo.forget());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,7 @@ void
PeerConnectionMedia::RemoveTransportFlow(int aIndex, bool aRtcp)
{
int index_inner = GetTransportFlowIndex(aIndex, aRtcp);
TransportFlow* flow = mTransportFlows[index_inner].forget().take();
if (flow) {
NS_ProxyRelease(GetSTSThread(), flow);
}
NS_ProxyRelease(GetSTSThread(), mTransportFlows[index_inner].forget());
}

void
Expand Down
2 changes: 1 addition & 1 deletion modules/libjar/nsJARChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ nsJARChannel::nsJARChannel()

nsJARChannel::~nsJARChannel()
{
NS_ReleaseOnMainThread(mLoadInfo);
NS_ReleaseOnMainThread(mLoadInfo.forget());

// release owning reference to the jar handler
nsJARProtocolHandler *handler = gJarHandler;
Expand Down
8 changes: 3 additions & 5 deletions netwerk/base/TLSServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,14 @@ TLSServerConnectionInfo::~TLSServerConnectionInfo()
return;
}

nsITLSServerSecurityObserver* observer;
RefPtr<nsITLSServerSecurityObserver> observer;
{
MutexAutoLock lock(mLock);
mSecurityObserver.forget(&observer);
observer = mSecurityObserver.forget();
}

if (observer) {
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
NS_ProxyRelease(mainThread, observer);
NS_ReleaseOnMainThread(observer.forget());
}
}

Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/nsBaseChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ nsBaseChannel::nsBaseChannel()

nsBaseChannel::~nsBaseChannel()
{
NS_ReleaseOnMainThread(mLoadInfo);
NS_ReleaseOnMainThread(mLoadInfo.forget());
}

nsresult
Expand Down
19 changes: 4 additions & 15 deletions netwerk/base/nsProtocolProxyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,20 @@ class nsAsyncResolveRequest final : public nsIRunnable
// main thread to delete safely, but if this request had its
// callbacks called normally they will all be null and this is a nop

nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));

if (mChannel) {
nsIChannel *forgettable;
mChannel.forget(&forgettable);
NS_ProxyRelease(mainThread, forgettable, false);
NS_ReleaseOnMainThread(mChannel.forget());
}

if (mCallback) {
nsIProtocolProxyCallback *forgettable;
mCallback.forget(&forgettable);
NS_ProxyRelease(mainThread, forgettable, false);
NS_ReleaseOnMainThread(mCallback.forget());
}

if (mProxyInfo) {
nsIProxyInfo *forgettable;
mProxyInfo.forget(&forgettable);
NS_ProxyRelease(mainThread, forgettable, false);
NS_ReleaseOnMainThread(mProxyInfo.forget());
}

if (mXPComPPS) {
nsIProtocolProxyService *forgettable;
mXPComPPS.forget(&forgettable);
NS_ProxyRelease(mainThread, forgettable, false);
NS_ReleaseOnMainThread(mXPComPPS.forget());
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions netwerk/base/nsServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,17 @@ nsServerSocket::OnSocketDetached(PRFileDesc *fd)
mListener->OnStopListening(this, mCondition);

// need to atomically clear mListener. see our Close() method.
nsIServerSocketListener *listener = nullptr;
RefPtr<nsIServerSocketListener> listener = nullptr;
{
MutexAutoLock lock(mLock);
mListener.swap(listener);
listener = mListener.forget();
}

// XXX we need to proxy the release to the listener's target thread to work
// around bug 337492.
if (listener)
NS_ProxyRelease(mListenerTarget, listener);
if (listener) {
NS_ProxyRelease(mListenerTarget, listener.forget());
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions netwerk/base/nsStreamListenerTee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ nsStreamListenerTee::OnStopRequest(nsIRequest *request,

// release sink on the same thread where the data was written (bug 716293)
if (mEventTarget) {
nsIOutputStream *sink = nullptr;
mSink.swap(sink);
if (NS_FAILED(NS_ProxyRelease(mEventTarget, sink))) {
NS_WARNING("Releasing sink on the current thread!");
NS_RELEASE(sink);
}
NS_ProxyRelease(mEventTarget, mSink.forget());
}
else {
mSink = 0;
Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/nsTransportUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class nsTransportEventSinkProxy : public nsITransportEventSink
{
// our reference to mSink could be the last, so be sure to release
// it on the target thread. otherwise, we could get into trouble.
NS_ProxyRelease(mTarget, mSink);
NS_ProxyRelease(mTarget, dont_AddRef(mSink));
}

public:
Expand Down
9 changes: 3 additions & 6 deletions netwerk/base/nsUDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,13 @@ nsUDPSocket::OnSocketDetached(PRFileDesc *fd)
if (mListener)
{
// need to atomically clear mListener. see our Close() method.
nsCOMPtr<nsIUDPSocketListener> listener;
RefPtr<nsIUDPSocketListener> listener = nullptr;
{
MutexAutoLock lock(mLock);
mListener.swap(listener);
listener = mListener.forget();
}

if (listener) {
listener->OnStopListening(this, mCondition);
NS_ProxyRelease(mListenerTarget, listener);
}
NS_ProxyRelease(mListenerTarget, listener.forget());
}
}

Expand Down
Loading

0 comments on commit 69cf7e0

Please sign in to comment.