Resolves bug #3450 (Improperly cleaning up resources in DllMain)
Merge pull request #2594 from arkunze:pullreq/140319-dll-shutdown-fix-b