Index: wp-includes/classes.php
===================================================================
--- wp-includes/classes.php	(revision 8110)
+++ wp-includes/classes.php	(working copy)
@@ -429,7 +429,8 @@
 		if ( $max_depth == 0 ||
 		     ($max_depth != 0 &&  $max_depth > $depth+1 )) { //whether to descend
 
-			for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) {
+			$num_elements = sizeof( $children_elements );
+			for ( $i = 0; $i < $num_elements; $i++ ) {
 
 				$child = $children_elements[$i];
 				if ( $child->$parent_field == $element->$id_field ) {
@@ -442,6 +443,7 @@
 					}
 
 					array_splice( $children_elements, $i, 1 );
+					$num_elements--;
 					$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
 					$i = -1;
 				}
Index: wp-includes/taxonomy.php
===================================================================
--- wp-includes/taxonomy.php	(revision 8110)
+++ wp-includes/taxonomy.php	(working copy)
@@ -410,10 +410,9 @@
 
 	$children = $terms[$term];
 
-	foreach ( $terms[$term] as $child ) {
+	foreach ( $terms[$term] as $child )
 		if ( isset($terms[$child]) )
 			$children = array_merge($children, get_term_children($child, $taxonomy));
-	}
 
 	return $children;
 }
@@ -1781,12 +1780,10 @@
 
 	$children = array();
 	$terms = get_terms($taxonomy, 'get=all');
-	foreach ( $terms as $term ) {
+	foreach ( $terms as $term )
 		if ( $term->parent > 0 )
 			$children[$term->parent][] = $term->term_id;
-	}
 	update_option("{$taxonomy}_children", $children);
-
 	return $children;
 }
 
@@ -1807,16 +1804,16 @@
  * @return array Empty if $terms is empty else returns full list of child terms.
  */
 function &_get_term_children($term_id, $terms, $taxonomy) {
-	$empty_array = array();
 	if ( empty($terms) )
-		return $empty_array;
+		return array();
 
-	$term_list = array();
 	$has_children = _get_term_hierarchy($taxonomy);
 
 	if  ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
-		return $empty_array;
+		return array();
 
+	$term_list = array();
+
 	foreach ( $terms as $term ) {
 		$use_id = false;
 		if ( !is_object($term) ) {
@@ -1830,15 +1827,12 @@
 			continue;
 
 		if ( $term->parent == $term_id ) {
-			if ( $use_id )
-				$term_list[] = $term->term_id;
-			else
-				$term_list[] = $term;
+			$term_list[] = $use_id ? $term->term_id : $term;
 
 			if ( !isset($has_children[$term->term_id]) )
 				continue;
 
-			if ( $children = _get_term_children($term->term_id, $terms, $taxonomy) )
+			if ( $children = _get_term_children($term->term_id, &$terms, $taxonomy) )
 				$term_list = array_merge($term_list, $children);
 		}
 	}

