fixed a bug where the dir resource was not closed in the directory helper, and made it more efficient

http://codeigniter.com/bug_tracker/bug/4206/
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index 5a23944..25c16c1 100644
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -45,22 +45,31 @@
 	{	

 		if ($fp = @opendir($source_dir))

 		{

+			$source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;		

 			$filedata = array();

+			

 			while (FALSE !== ($file = readdir($fp)))

 			{

-				if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)

+				if (substr($file, 0, 1) == '.')

+				{

+					continue;

+				}

+				

+				if ($top_level_only == FALSE && @is_dir($source_dir.$file))

 				{

 					$temp_array = array();

 				

-					$temp_array = directory_map($source_dir.$file."/");

+					$temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR);

 				

 					$filedata[$file] = $temp_array;

 				}

-				elseif (substr($file, 0, 1) != ".")

+				else

 				{

 					$filedata[] = $file;

 				}

 			}

+			

+			closedir($fp);

 			return $filedata;

 		}

 	}