  extern "C" {
  
    static BOOL CALLBACK ELM_Callback(WIN32_ELMCB_PCSTR ModuleName,
-@@ -48,6 +41,8 @@ extern "C" {
-                                     ULONG ModuleSize,
-                                     PVOID UserContext)
-   {
-+    static DenseSet<HMODULE> ProcessDynLibs;
-+
-     // Ignore VC++ runtimes prior to 7.1.  Somehow some of them get loaded
-     // into the process.
-     if (stricmp(ModuleName, "msvci70") != 0 &&
-@@ -63,49 +58,60 @@ extern "C" {
+@@ -63,49 +55,61 @@ extern "C" {
  #endif
          stricmp(ModuleName, "msvcrt20") != 0 &&
          stricmp(ModuleName, "msvcrt40") != 0) {
 -      OpenedHandles->insert((HMODULE)ModuleBase);
-+      if (ProcessDynLibs.insert((HMODULE)ModuleBase).second)
-+        ++(*OpenedHandles)[(HMODULE)ModuleBase];
++      OpenedHandles->insert[(HMODULE)ModuleBase];
      }
      return TRUE;
    }

-    FreeLibrary(a_handle);
+bool CloseLibraryImpl(void *DlHandle, std::string *ErrMsg) {
+  if (!FreeLibrary((HMODULE)DlHandle)) {
+    MakeErrMsg(ErrMsg, "Cannot free DLL: ");
+    return false;
+  }
+  return true;

     // When no file is specified, enumerate all DLLs and EXEs in the process.
     if (OpenedHandles == 0)
-      OpenedHandles = new DenseSet<HMODULE>();
+      OpenedHandles = new DenseSet<void *>();
 
     EnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);
     // Dummy library that represents "search all handles".
