nsNullPrincipal::Release() { NS_PRECONDITION(0 != mJSPrincipals.refcount, "dup release"); nsrefcnt count = PR_ATOMIC_DECREMENT(&mJSPrincipals.refcount); NS_LOG_RELEASE(this, count, "nsNullPrincipal"); if (count == 0) { delete this; } return count; }
nsrefcnt nsTransactionItem::Release() { --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "nsTransactionItem"); if (mRefCnt == 0) { mRefCnt = 1; delete this; return 0; } return mRefCnt; }
CacheFile::Release() { NS_PRECONDITION(0 != mRefCnt, "dup release"); nsrefcnt count = --mRefCnt; NS_LOG_RELEASE(this, count, "CacheFile"); MOZ_ASSERT(count != 0, "Unexpected"); if (count == 1) { bool deleteFile = false; // Not using CacheFileAutoLock since it hard-refers the file // and in it's destructor reenters this method. Lock(); if (mMemoryOnly) { deleteFile = true; } else if (mMetadata) { WriteMetadataIfNeeded(); if (mWritingMetadata) { MOZ_ASSERT(mRefCnt > 1); } else { if (mRefCnt == 1) deleteFile = true; } } Unlock(); if (!deleteFile) { return count; } NS_LOG_RELEASE(this, 0, "CacheFile"); delete (this); return 0; } return count; }
CEnumFormatEtc::Release() { uint32_t refReturn; refReturn = --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "CEnumFormatEtc"); if (mRefCnt == 0) delete this; return refReturn; }
nsrefcnt PyG_Base::Release(void) { nsrefcnt cnt = (nsrefcnt) PR_AtomicDecrement((PRInt32*)&mRefCnt); #ifdef NS_BUILD_REFCNT_LOGGING if (m_pBaseObject == NULL) NS_LOG_RELEASE(this, cnt, refcntLogRepr); #endif if ( cnt == 0 ) delete this; return cnt; }
void HRTFDatabaseLoader::MainThreadRelease() { MOZ_ASSERT(NS_IsMainThread()); int count = --m_refCnt; MOZ_ASSERT(count >= 0, "extra release"); NS_LOG_RELEASE(this, count, "HRTFDatabaseLoader"); if (count == 0) { // It is safe to delete here as the first reference can only be added // on this (main) thread. delete this; } }
NS_IMETHODIMP_(nsrefcnt) xpctestNoisy::Release(void) { NS_PRECONDITION(0 != mRefCnt, "dup release"); --mRefCnt; printf("Noisy %d - decremented refcount to %d\n", mID, mRefCnt.get()); NS_LOG_RELEASE(this, mRefCnt, "xpctestNoisy"); if (mRefCnt == 0) { NS_DELETEXPCOM(this); return 0; } return mRefCnt; }
nsrefcnt nsHtml5OwningUTF16Buffer::Release() { NS_PRECONDITION(0 != mRefCnt, "Release without AddRef."); --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "nsHtml5OwningUTF16Buffer"); if (mRefCnt == 0) { mRefCnt = 1; /* stabilize */ delete this; return 0; } return mRefCnt; }
NS_IMETHODIMP_(nsrefcnt) npAPInsIInputStreamShim::Release(void) { NS_PRECONDITION(0 != mRefCnt, "dup release"); // Note that we intentionally don't check for owning thread safety. --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "npAPInsIInputStreamShim"); if (mRefCnt == 0) { mRefCnt = 1; /* stabilize */ NS_DELETEXPCOM(this); return 0; } return mRefCnt; }
void txAExprResult::Release() { --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "txAExprResult"); if (mRefCnt == 0) { if (mRecycler) { mRecycler->recycle(this); } else { delete this; } } }
nsrefcnt nsNodeInfoManager::Release() { NS_PRECONDITION(0 != mRefCnt, "dup release"); nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); NS_LOG_RELEASE(this, count, "nsNodeInfoManager"); if (count == 0) { mRefCnt = 1; /* stabilize */ delete this; } return count; }
nsHttpTransaction::Release() { nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); count = PR_AtomicDecrement((PRInt32 *) &mRefCnt); NS_LOG_RELEASE(this, count, "nsHttpTransaction"); if (0 == count) { mRefCnt = 1; /* stablize */ // it is essential that the transaction be destroyed on the consumer // thread (we could be holding the last reference to our consumer). DeleteSelfOnConsumerThread(); return 0; } return count; }
STDMETHODIMP_(ULONG) CEnumFormatEtc::Release(void) { ULONG cRefT; cRefT = --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "CEnumFormatEtc"); if (0L == mRefCnt) delete this; #ifdef DEBUG //printf("CEnumFormatEtc::Release >>>>>>>>>>>>>>>>>> %d on %p\n", mRefCnt, this); #endif return cRefT; }
nsrefcnt nsXPCWrappedJS::Release(void) { NS_PRECONDITION(0 != mRefCnt, "dup release"); if (mMainThreadOnly && !NS_IsMainThread()) { // We'd like to abort here, but this can happen if someone uses a proxy // for the nsXPCWrappedJS. nsCOMPtr<nsIThread> mainThread = do_GetMainThread(); // If we can't get the main thread anymore we just leak, but this really // shouldn't happen. NS_ASSERTION(mainThread, "Can't get main thread, leaking nsXPCWrappedJS!"); if (mainThread) { NS_ProxyRelease(mainThread, static_cast<nsIXPConnectWrappedJS*>(this)); } return mRefCnt; } // need to take the map lock here to prevent GetNewOrUsed from trying // to reuse a wrapper on one thread while it's being destroyed on another XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); XPCAutoLock lock(rt->GetMapLock()); do_decrement: nsrefcnt cnt = NS_AtomicDecrementRefcnt(mRefCnt); NS_LOG_RELEASE(this, cnt, "nsXPCWrappedJS"); if (0 == cnt) { delete this; // also unlinks us from chain return 0; } if (1 == cnt) { if (IsValid()) RemoveFromRootSet(rt->GetMapLock()); // If we are not the root wrapper or if we are not being used from a // weak reference, then this extra ref is not needed and we can let // ourself be deleted. // Note: HasWeakReferences() could only return true for the root. if (!HasWeakReferences()) goto do_decrement; } return cnt; }
nsCacheEntryDescriptor::nsDecompressInputStreamWrapper::Release() { // Holding a reference to descriptor ensures that cache service won't go // away. Do not grab cache service lock if there is no descriptor. nsRefPtr<nsCacheEntryDescriptor> desc; { mozilla::MutexAutoLock lock(mLock); desc = mDescriptor; } if (desc) nsCacheService::Lock(LOCK_TELEM( NSDECOMPRESSINPUTSTREAMWRAPPER_RELEASE)); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); count = --mRefCnt; NS_LOG_RELEASE(this, count, "nsCacheEntryDescriptor::nsDecompressInputStreamWrapper"); if (0 == count) { // don't use desc here since mDescriptor might be already nulled out if (mDescriptor) { NS_ASSERTION(mDescriptor->mInputWrappers.IndexOf(this) != -1, "Wrapper not found in array!"); mDescriptor->mInputWrappers.RemoveElement(this); } if (desc) nsCacheService::Unlock(); mRefCnt = 1; delete (this); return 0; } if (desc) nsCacheService::Unlock(); return count; }
nsJavaXPTCStub::ReleaseInternal() { NS_PRECONDITION(0 != mRefCnt, "dup release"); NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub); --mRefCnt; NS_LOG_RELEASE(this, mRefCnt, "nsJavaXPTCStub"); if (mRefCnt == 0) { // delete strong ref; allows Java object to be garbage collected DeleteStrongRef(); // If we have a weak ref, we don't delete this object. if (mWeakRefCnt == 0) { mRefCnt = 1; /* stabilize */ Destroy(); delete this; } return 0; } return mRefCnt; }
NS_IMETHODIMP_(MozExternalRefCountType) SharedThreadPool::Release(void) { MOZ_ASSERT(sMonitor); bool dispatchShutdownEvent; { ReentrantMonitorAutoEnter mon(*sMonitor); nsrefcnt count = --mRefCnt; NS_LOG_RELEASE(this, count, "SharedThreadPool"); if (count) { return count; } // Zero refcount. Must shutdown and then delete the thread pool. // First, dispatch an event to the main thread to call Shutdown() on // the nsIThreadPool. The Runnable here will add a refcount to the pool, // and when the Runnable releases the nsIThreadPool it will be deleted. RefPtr<nsIRunnable> r = NS_NewRunnableMethod(mPool, &nsIThreadPool::Shutdown); NS_DispatchToMainThread(r); // Remove SharedThreadPool from table of pools. sPools->Remove(mName); MOZ_ASSERT(!sPools->Get(mName)); // Stabilize refcount, so that if something in the dtor QIs, // it won't explode. mRefCnt = 1; delete this; dispatchShutdownEvent = sPools->Count() == 0; } if (dispatchShutdownEvent) { // No more SharedThreadPools alive. Destroy the hash table. // Ensure that we only run on the main thread. // Do this in an event so that if something holds the monitor we won't // be deleting the monitor while it's held. NS_DispatchToMainThread(new ShutdownPoolsEvent()); } return 0; }
nsrefcnt nsLDAPConnection::Release(void) { nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); NS_LOG_RELEASE(this, count, "nsLDAPConnection"); if (0 == count) { // As commented by danm: In the object's destructor, if by some // convoluted, indirect means it happens to run into some code // that temporarily references it (addref/release), then if the // refcount had been left at 0 the unexpected release would // attempt to reenter the object's destructor. // mRefCnt = 1; /* stabilize */ // If we have a mRunnable object, we need to make sure to lock it's // mLock before we try to DELETE. This is to avoid a race condition. // We also make sure to keep a strong reference to the runnable // object, to make sure it doesn't get GCed from underneath us, // while we are still holding a lock for instance. // if (mRunnable && mRunnable->mLock) { nsLDAPConnectionLoop *runnable = mRunnable; NS_ADDREF(runnable); PR_Lock(runnable->mLock); NS_DELETEXPCOM(this); PR_Unlock(runnable->mLock); NS_RELEASE(runnable); } else { NS_DELETEXPCOM(this); } return 0; } return count; }
nsCacheEntryDescriptor::nsCompressOutputStreamWrapper::Release() { // Holding a reference to descriptor ensures that cache service won't go // away. Do not grab cache service lock if there is no descriptor. nsRefPtr<nsCacheEntryDescriptor> desc; { mozilla::MutexAutoLock lock(mLock); desc = mDescriptor; } if (desc) nsCacheService::Lock(LOCK_TELEM(NSCOMPRESSOUTPUTSTREAMWRAPPER_RELEASE)); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); count = --mRefCnt; NS_LOG_RELEASE(this, count, "nsCacheEntryDescriptor::nsCompressOutputStreamWrapper"); if (0 == count) { // don't use desc here since mDescriptor might be already nulled out if (mDescriptor) mDescriptor->mOutputWrapper = nullptr; if (desc) nsCacheService::Unlock(); mRefCnt = 1; delete (this); return 0; } if (desc) nsCacheService::Unlock(); return count; }
nsrefcnt xptiInterfaceInfo::Release(void) { xptiInterfaceEntry* entry = mEntry; nsrefcnt cnt = NS_AtomicDecrementRefcnt(mRefCnt); NS_LOG_RELEASE(this, cnt, "xptiInterfaceInfo"); if(!cnt) { nsAutoMonitor lock(xptiInterfaceInfoManager::GetInfoMonitor()); LOG_INFO_MONITOR_ENTRY; // If GetInterfaceInfo added and *released* a reference before we // acquired the monitor then 'this' might already be dead. In that // case we would not want to try to access any instance data. We // would want to bail immediately. If 'this' is already dead then the // entry will no longer have a pointer to 'this'. So, we can protect // ourselves from danger without more aggressive locking. if(entry && !entry->InterfaceInfoEquals(this)) return 0; // If GetInterfaceInfo added a reference before we acquired the monitor // then we want to bail out of here without destorying the object. if(mRefCnt) return 1; if(mEntry) { mEntry->LockedInterfaceInfoDeathNotification(); mEntry = nsnull; } delete this; return 0; } return cnt; }
NS_IMETHODIMP_(MozExternalRefCountType) SharedThreadPool::Release(void) { MOZ_ASSERT(sMonitor); ReentrantMonitorAutoEnter mon(*sMonitor); nsrefcnt count = --mRefCnt; NS_LOG_RELEASE(this, count, "SharedThreadPool"); if (count) { return count; } // Remove SharedThreadPool from table of pools. sPools->Remove(mName); MOZ_ASSERT(!sPools->Get(mName)); // Dispatch an event to the main thread to call Shutdown() on // the nsIThreadPool. The Runnable here will add a refcount to the pool, // and when the Runnable releases the nsIThreadPool it will be deleted. NS_DispatchToMainThread(NewRunnableMethod(mPool, &nsIThreadPool::Shutdown)); // Stabilize refcount, so that if something in the dtor QIs, it won't explode. mRefCnt = 1; delete this; return 0; }