From 9ce90775c2d9001e5c9fc397a6279c1453012396 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 27 Nov 2009 12:21:44 +0000 Subject: [PATCH] From Chris Denham, "I discovered what seems to be a missing call to FreeLibrary for osgDB.dll The result of this is that it prevents me from dynamically unloading my DLL (which uses OSG). This is because initialisation of the osg::Registry instance results in a call to GetModuleHandleEx (to get the filename of the DLL). This call to GetModuleHandleEx increments the module refcount, but there was no matching call to FreeLibrary for the returned handle. Unlike the old GetModuleHandle function, GetModuleHandle does (by default) increment the refcount. I have added the missing call to FreeLibrary in osgDB::FileUtils., and now my the runtime unload of MY dll is working properly. It has also cured some related problems I was having with memory leak checks being reported. I have attached a fix to osgDB/FileUtils.cpp based on version 2.9.5 svn revision 10374 " --- src/osgDB/FileUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 8e6ab32a1..4999fcf87 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -651,6 +651,7 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) osg::notify(osg::WARN) << "Could not get dll directory " "using Win32 API. It will not be searched." << std::endl; } + FreeLibrary(thisModule); } else {