From aab195a6eb3f833114a679936228122ad6d6d0bf Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Mon, 19 Nov 2012 04:42:02 +0100 Subject: [PATCH] Fix deinitialization order fiasco. --- indra/llmessage/aicurlperhost.cpp | 11 ++++++++--- indra/llmessage/aicurlperhost.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/indra/llmessage/aicurlperhost.cpp b/indra/llmessage/aicurlperhost.cpp index 724d5bccd..7f7490865 100644 --- a/indra/llmessage/aicurlperhost.cpp +++ b/indra/llmessage/aicurlperhost.cpp @@ -56,12 +56,17 @@ PerHostRequestQueuePtr PerHostRequestQueue::instance(std::string const& hostname //static void PerHostRequestQueue::release(PerHostRequestQueuePtr& instance) { - if (instance->lastone()) + if (instance->exactly_two_left()) // Being 'instance' and the one in sInstanceMap. { + // The viewer can be have left main() we can't access the global sInstanceMap anymore. + if (LLApp::isStopped()) + { + return; + } instance_map_wat instance_map_w(sInstanceMap); - // It is possible that 'lastone' is not up to date anymore. + // It is possible that 'exactly_two_left' is not up to date anymore. // Therefore, recheck the condition now that we have locked sInstanceMap. - if (!instance->lastone()) + if (!instance->exactly_two_left()) { // Some other thread added this host in the meantime. return; diff --git a/indra/llmessage/aicurlperhost.h b/indra/llmessage/aicurlperhost.h index dac9d70c0..c464d490c 100644 --- a/indra/llmessage/aicurlperhost.h +++ b/indra/llmessage/aicurlperhost.h @@ -118,7 +118,7 @@ class PerHostRequestQueue { class RefCountedThreadSafePerHostRequestQueue : public threadsafe_PerHostRequestQueue { public: RefCountedThreadSafePerHostRequestQueue(void) : mReferenceCount(0) { } - bool lastone(void) const { llassert(mReferenceCount >= 2); return mReferenceCount == 2; } + bool exactly_two_left(void) const { return mReferenceCount == 2; } private: // Used by PerHostRequestQueuePtr. Object is deleted when reference count reaches zero.