Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 5683)
+++ wp-includes/theme.php	(working copy)
@@ -118,46 +118,50 @@
 	$theme_loc = str_replace(ABSPATH, '', $theme_root);
 
 	// Files in wp-content/themes directory and one subdir down
-	$themes_dir = @ dir($theme_root);
+	$themes_dir = @ opendir($theme_root);
 	if ( !$themes_dir )
 		return false;
 
-	while ( ($theme_dir = $themes_dir->read()) !== false ) {
+	while ( ($theme_dir = readdir($themes_dir)) !== false ) {
 		if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
 			if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
 				continue;
-			$stylish_dir = @ dir($theme_root . '/' . $theme_dir);
+			$stylish_dir = @ opendir($theme_root . '/' . $theme_dir);
 			$found_stylesheet = false;
-			while ( ($theme_file = $stylish_dir->read()) !== false ) {
+			while ( ($theme_file = readdir($stylish_dir)) !== false ) {
 				if ( $theme_file == 'style.css' ) {
 					$theme_files[] = $theme_dir . '/' . $theme_file;
 					$found_stylesheet = true;
 					break;
 				}
 			}
+			@closedir($stylish_dir);
 			if ( !$found_stylesheet ) { // look for themes in that dir
 				$subdir = "$theme_root/$theme_dir";
 				$subdir_name = $theme_dir;
-				$theme_subdir = @dir( $subdir );
-				while ( ($theme_dir = $theme_subdir->read()) !== false ) {
+				$theme_subdir = @ opendir( $subdir );
+				while ( ($theme_dir = readdir($theme_subdir)) !== false ) {
 					if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
 						if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
 							continue;
-						$stylish_dir = @ dir($subdir . '/' . $theme_dir);
+						$stylish_dir = @ opendir($subdir . '/' . $theme_dir);
 						$found_stylesheet = false;
-						while ( ($theme_file = $stylish_dir->read()) !== false ) {
+						while ( ($theme_file = readdir($stylish_dir)) !== false ) {
 							if ( $theme_file == 'style.css' ) {
 								$theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
 								$found_stylesheet = true;
 								break;
 							}
 						}
+						@closedir($stylish_dir);
 					}
 				}
+				@closedir($theme_subdir);
 				$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
 			}
 		}
 	}
+	@closedir($theme_dir);
 
 	if ( !$themes_dir || !$theme_files )
 		return $themes;
Index: wp-admin/includes/plugin.php
===================================================================
--- wp-admin/includes/plugin.php	(revision 5683)
+++ wp-admin/includes/plugin.php	(working copy)
@@ -42,15 +42,15 @@
 	$plugin_root = ABSPATH . PLUGINDIR;
 
 	// Files in wp-content/plugins directory
-	$plugins_dir = @ dir( $plugin_root);
+	$plugins_dir = @ opendir( $plugin_root);
 	if ( $plugins_dir ) {
-		while (($file = $plugins_dir->read() ) !== false ) {
+		while (($file = readdir( $plugins_dir ) ) !== false ) {
 			if ( substr($file, 0, 1) == '.' )
 				continue;
 			if ( is_dir( $plugin_root.'/'.$file ) ) {
-				$plugins_subdir = @ dir( $plugin_root.'/'.$file );
+				$plugins_subdir = @ opendir( $plugin_root.'/'.$file );
 				if ( $plugins_subdir ) {
-					while (($subfile = $plugins_subdir->read() ) !== false ) {
+					while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
 						if ( substr($subfile, 0, 1) == '.' )
 							continue;
 						if ( substr($subfile, -4) == '.php' )
@@ -63,6 +63,8 @@
 			}
 		}
 	}
+	@closedir( $plugins_dir );
+	@closedir( $plugins_subdir );
 
 	if ( !$plugins_dir || !$plugin_files )
 		return $wp_plugins;
@@ -377,4 +379,4 @@
 	return true;
 }
 
-?>
\ No newline at end of file
+?>
Index: wp-admin/includes/upgrade.php
===================================================================
--- wp-admin/includes/upgrade.php	(revision 5683)
+++ wp-admin/includes/upgrade.php	(working copy)
@@ -1089,9 +1089,9 @@
 	// Copy files from the default theme to the site theme.
 	//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
 
-	$theme_dir = @ dir("$default_dir");
+	$theme_dir = @ opendir("$default_dir");
 	if ($theme_dir) {
-		while(($theme_file = $theme_dir->read()) !== false) {
+		while(($theme_file = readdir( $theme_dir )) !== false) {
 			if (is_dir("$default_dir/$theme_file"))
 				continue;
 			if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
@@ -1099,6 +1099,7 @@
 			chmod("$site_dir/$theme_file", 0777);
 		}
 	}
+	@closedir($theme_dir);
 
 	// Rewrite the theme header.
 	$stylelines = explode("\n", implode('', file("$site_dir/style.css")));
@@ -1122,9 +1123,9 @@
 		return false;
 	}
 
-	$images_dir = @ dir("$default_dir/images");
+	$images_dir = @ opendir("$default_dir/images");
 	if ($images_dir) {
-		while(($image = $images_dir->read()) !== false) {
+		while(($image = readdir($images_dir)) !== false) {
 			if (is_dir("$default_dir/images/$image"))
 				continue;
 			if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
@@ -1132,6 +1133,7 @@
 			chmod("$site_dir/images/$image", 0777);
 		}
 	}
+	@closedir($images_dir);
 }
 
 // Create a site theme from the default theme.
@@ -1218,4 +1220,4 @@
 	}
 }
 
-?>
\ No newline at end of file
+?>
Index: wp-admin/import.php
===================================================================
--- wp-admin/import.php	(revision 5683)
+++ wp-admin/import.php	(working copy)
@@ -14,9 +14,9 @@
 // Load all importers so that they can register.
 $import_loc = 'wp-admin/import';
 $import_root = ABSPATH.$import_loc;
-$imports_dir = @ dir($import_root);
+$imports_dir = @ opendir($import_root);
 if ($imports_dir) {
-	while (($file = $imports_dir->read()) !== false) {
+	while (($file = readdir($imports_dir) !== false) {
 		if ($file{0} == '.') {
 			continue;
 		} elseif (substr($file, -4) == '.php') {
@@ -24,6 +24,7 @@
 		}
 	}
 }
+@closedir($imports_dir);
 
 $importers = get_importers();
 
