diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp
index 8a8791131572f6b58a8ae43607cfcbdbe86c421b..0556fadb266e15ff2e6224eb3131f584e6ceb79e 100644
--- a/indra/llcommon/llapr.cpp
+++ b/indra/llcommon/llapr.cpp
@@ -38,12 +38,15 @@ apr_thread_mutex_t *gCallStacksLogMutexp = NULL;
 
 const S32 FULL_VOLATILE_APR_POOL = 1024 ; //number of references to LLVolatileAPRPool
 
+bool gAPRInitialized = false;
+
 void ll_init_apr()
 {
+	// Initialize APR and create the global pool
+	apr_initialize();
+	
 	if (!gAPRPoolp)
 	{
-		// Initialize APR and create the global pool
-		apr_initialize();
 		apr_pool_create(&gAPRPoolp, NULL);
 		
 		// Initialize the logging mutex
@@ -57,11 +60,19 @@ void ll_init_apr()
 	}
 
 	LLThreadLocalPointerBase::initAllThreadLocalStorage();
+	gAPRInitialized = true;
 }
 
 
-void ll_cleanup_apr(bool destroy_pools)
+bool ll_apr_is_initialized()
+{
+	return gAPRInitialized;
+}
+
+void ll_cleanup_apr()
 {
+	gAPRInitialized = false;
+
 	LL_INFOS("APR") << "Cleaning up APR" << LL_ENDL;
 
 	if (gLogMutexp)
@@ -83,7 +94,7 @@ void ll_cleanup_apr(bool destroy_pools)
 
 	LLThreadLocalPointerBase::destroyAllThreadLocalStorage();
 
-	if (gAPRPoolp && destroy_pools)
+	if (gAPRPoolp)
 	{
 		apr_pool_destroy(gAPRPoolp);
 		gAPRPoolp = NULL;
diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h
index 424ddc6505be80e79b07c54a70ee09e87f82bcb8..3b65c0dc342f3b4b0cdbece93870d6df10f1d49d 100644
--- a/indra/llcommon/llapr.h
+++ b/indra/llcommon/llapr.h
@@ -70,7 +70,10 @@ void LL_COMMON_API ll_init_apr();
 /** 
  * @brief Cleanup those common apr constructs.
  */
-void LL_COMMON_API ll_cleanup_apr(bool destroy_pools = true);
+void LL_COMMON_API ll_cleanup_apr();
+
+bool LL_COMMON_API ll_apr_is_initialized();
+
 
 //
 //LL apr_pool
diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp
index b685bb4d60cff085f250e94c59237fb97814c9f7..ad0287c6d562f3162c2fe965eab31165932c6154 100644
--- a/indra/llcommon/llmutex.cpp
+++ b/indra/llcommon/llmutex.cpp
@@ -56,12 +56,15 @@ LLMutex::~LLMutex()
 	//bad assertion, the subclass LLSignal might be "locked", and that's OK
 	//llassert_always(!isLocked()); // better not be locked!
 #endif
-	apr_thread_mutex_destroy(mAPRMutexp);
-	mAPRMutexp = NULL;
-	if (mIsLocalPool)
+	if (ll_apr_is_initialized())
 	{
-		apr_pool_destroy(mAPRPoolp);
+		apr_thread_mutex_destroy(mAPRMutexp);
+		if (mIsLocalPool)
+		{
+			apr_pool_destroy(mAPRPoolp);
+		}
 	}
+	mAPRMutexp = NULL;
 }
 
 
diff --git a/indra/llcorehttp/_refcounted.h b/indra/llcorehttp/_refcounted.h
index 21a916b13b1dd0a6bf75ca04d3642ee3757274f6..402e7251524d1642b5a333b1534a8b49cb35c6aa 100644
--- a/indra/llcorehttp/_refcounted.h
+++ b/indra/llcorehttp/_refcounted.h
@@ -72,7 +72,7 @@ class RefCounted
 
 inline void RefCounted::addRef() const
 {
-	S32 count(mRefCount++);
+	S32 count(++mRefCount);
 	llassert_always(count >= 0);
 }
 
@@ -82,7 +82,7 @@ inline void RefCounted::release() const
 	S32 count(mRefCount);
 	llassert_always(count != NOT_REF_COUNTED);
 	llassert_always(count > 0);
-	count = mRefCount--;
+	count = --mRefCount;
 
 	// clean ourselves up if that was the last reference
 	if (0 == count)
diff --git a/indra/llmessage/llproxy.cpp b/indra/llmessage/llproxy.cpp
index aa474fabd2bbbe2c3034a7a40e2062a977567dbd..9b8d19cc3e2e0c0f1f8af2b985bae1686a85415a 100644
--- a/indra/llmessage/llproxy.cpp
+++ b/indra/llmessage/llproxy.cpp
@@ -61,8 +61,11 @@ LLProxy::LLProxy():
 
 LLProxy::~LLProxy()
 {
-	stopSOCKSProxy();
-	disableHTTPProxy();
+	if (ll_apr_is_initialized())
+	{
+		stopSOCKSProxy();
+		disableHTTPProxy();
+	}
 }
 
 /**
diff --git a/indra/test/io.cpp b/indra/test/io.cpp
index ce747f667d2d53e0ed78b4d1640b5432877309cd..f2b4a5339c334fb5de32a29830c5ca6298b3da68 100644
--- a/indra/test/io.cpp
+++ b/indra/test/io.cpp
@@ -44,6 +44,7 @@
 #include "llsdrpcclient.h"
 #include "llsdrpcserver.h"
 #include "llsdserialize.h"
+#include "llcommon.h"
 #include "lluuid.h"
 #include "llinstantmessage.h"
 
@@ -830,6 +831,7 @@ namespace tut
 	public:
 		PumpAndChainTestData()
 		{
+			LLCommon::initClass();
 			apr_pool_create(&mPool, NULL);
 			mPump = new LLPumpIO(mPool);
 		}
@@ -839,6 +841,7 @@ namespace tut
 			mChain.clear();
 			delete mPump;
 			apr_pool_destroy(mPool);
+			LLCommon::cleanupClass();
 		}
 	};
 	typedef test_group<PumpAndChainTestData>	PumpAndChainTestGroup;
@@ -909,6 +912,7 @@ namespace tut
 		
 		pipe_and_pump_fitness()
 		{
+			LLCommon::initClass();
 			LLFrameTimer::updateFrameTime();
 			apr_pool_create(&mPool, NULL);
 			mPump = new LLPumpIO(mPool);
@@ -923,6 +927,7 @@ namespace tut
 			mSocket.reset();
 			delete mPump;
 			apr_pool_destroy(mPool);
+			LLCommon::cleanupClass();
 		}
 
 	protected:
@@ -1186,8 +1191,12 @@ namespace tut
 			LLSimpleRPCResponse(LLSD* response) :
 				mResponsePtr(response)
 			{
+				LLCommon::initClass();
+			}
+			~LLSimpleRPCResponse() 
+			{
+				LLCommon::cleanupClass();
 			}
-			~LLSimpleRPCResponse() {}
 			virtual bool response(LLPumpIO* pump)
 			{
 				*mResponsePtr = mReturnValue;
diff --git a/indra/test/llhttpdate_tut.cpp b/indra/test/llhttpdate_tut.cpp
index 46684bb9dc0cc425418582944ef411e4378af6f2..d6f0ba5e66eec564881dd99122f43ac256a8346a 100644
--- a/indra/test/llhttpdate_tut.cpp
+++ b/indra/test/llhttpdate_tut.cpp
@@ -29,6 +29,7 @@
 #include "lltut.h"
 
 #include "lldate.h"
+#include "llcommon.h"
 #include "llframetimer.h"
 
 #include <time.h>
@@ -38,6 +39,14 @@ namespace tut
 {
     struct httpdate_data
     {
+		httpdate_data() 
+		{ 
+			LLCommon::initClass();
+		}
+		~httpdate_data() 
+		{ 
+			LLCommon::cleanupClass();
+		}
         LLDate some_date;
     };
     typedef test_group<httpdate_data> httpdate_test;
diff --git a/indra/test/lliohttpserver_tut.cpp b/indra/test/lliohttpserver_tut.cpp
index 2fdc455f45fc01874299a95cc603a8b57ddba7f6..e7af09f80b0441ef63df22aacb3ac5b46c087d4b 100644
--- a/indra/test/lliohttpserver_tut.cpp
+++ b/indra/test/lliohttpserver_tut.cpp
@@ -31,6 +31,7 @@
 #include "lliohttpserver.h"
 #include "llsdhttpserver.h"
 #include "llsdserialize.h"
+#include "llcommon.h"
 
 #include "llpipeutil.h"
 
@@ -76,11 +77,17 @@ namespace tut
 		HTTPServiceTestData()
 			: mResponse(NULL)
 		{
+			LLCommon::initClass();
 			LLHTTPStandardServices::useServices();
 			LLHTTPRegistrar::buildAllServices(mRoot);
 			mRoot.addNode("/delayed/echo", new DelayedEcho(this));
 			mRoot.addNode("/wire/hello", new LLHTTPNodeForPipe<WireHello>);
 		}
+
+		~HTTPServiceTestData()
+		{
+			LLCommon::cleanupClass();
+		}
 		
 		LLHTTPNode mRoot;
 		LLHTTPNode::ResponsePtr mResponse;
diff --git a/indra/test/test.cpp b/indra/test/test.cpp
index d75040393cc749723213bdb926a1ef464fb85f7f..8bd302ce7a9a9eb9967bc8b9f7d7ddfb40c118bb 100644
--- a/indra/test/test.cpp
+++ b/indra/test/test.cpp
@@ -643,7 +643,7 @@ int main(int argc, char **argv)
 		s.close();
 	}
 
-	ll_cleanup_apr(false);
+	ll_cleanup_apr();
 
 	int retval = (success ? 0 : 1);
 	return retval;