Index: /trunk/source/level-0/l0-cfm-support.lisp
===================================================================
--- /trunk/source/level-0/l0-cfm-support.lisp	(revision 14644)
+++ /trunk/source/level-0/l0-cfm-support.lisp	(revision 14645)
@@ -115,6 +115,7 @@
       (maphash #'(lambda (k fv)
                    (declare (ignore k))
-                   (when (eq (fv.container fv) lib)
-                     (setf (fv.addr fv) nil)))
+                   (when (fv.addr fv)
+                     (when (or (null lib) (eq (fv.container fv) lib))
+                       (setf (fv.addr fv) nil))))
                fvs))))
 
@@ -433,7 +434,8 @@
     (maphash #'(lambda (k eep)
 		 (declare (ignore k))
-		 (when (eq (eep.container eep) lib)
-		   (setf (eep.address eep) nil)
-		   (incf count)))
+                 (when (eep.address eep)
+                   (when (or (null lib) (eq (eep.container eep) lib))
+                     (setf (eep.address eep) nil)
+                     (incf count))))
 	     (eeps))    
     (not (zerop count))))
Index: /trunk/source/level-1/linux-files.lisp
===================================================================
--- /trunk/source/level-1/linux-files.lisp	(revision 14644)
+++ /trunk/source/level-1/linux-files.lisp	(revision 14645)
@@ -976,8 +976,19 @@
 )
         
-                      
+(defun %probe-shared-library (shlib)
+  #-(or windows-target freebsd-target)
+  (with-cstrs ((name (shlib.pathname shlib)))
+    (not (%null-ptr-p (#_dlopen name (logior #$RTLD_NOW #$RTLD_NOLOAD)))))
+  ;; FreeBSD may support #$RTLD_NOLOAD in 8.0, and that support may
+  ;; have been backported to 7.2.  Until then ...
+  #+freebsd-target                      
+  (rlet ((info #>Dl_info))
+    (not (eql 0 (#_dladdr (shlib.base shlib) info))))
+  #+windows-target
+  (with-filename-cstrs ((name (shlib.pathname shlib)))
+    (not (%null-ptr-p (#_FindModuleW name)))))
+
 
 ;;; Kind of has something to do with files, and doesn't work in level-0.
-#+(or linux-target freebsd-target solaris-target)
 (defun close-shared-library (lib &key (completely t))
   "If completely is T, set the reference count of library to 0. Otherwise,
@@ -991,18 +1002,19 @@
 	 (handle (shlib.handle lib)))
       (when handle
-	(let* ((found nil)
-	       (base (shlib.base lib)))
+	(let* ((found nil))
 	  (do* ()
-	       ((progn		  
-		  (#_dlclose handle)
-		  (or (not (setq found (shlib-containing-address base)))
+	       ((progn
+                  #-windows-target (#_dlclose handle)
+                  #+windows-target (#_FreeLibrary handle)
+		  (or (not (setq found
+                                 (%probe-shared-library lib)))
 		      (not completely)))))
 	  (when (not found)
 	    (setf (shlib.pathname lib) nil
-	      (shlib.base lib) nil
-              (shlib.handle lib) nil
-	      (shlib.map lib) nil)
-            (unload-foreign-variables lib)
-	    (unload-library-entrypoints lib))))))
+                  (shlib.base lib) nil
+                  (shlib.handle lib) nil
+                  (shlib.map lib) nil)
+            (unload-foreign-variables nil)
+	    (unload-library-entrypoints nil))))))
 
 #+darwin-target
