File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -610,6 +610,7 @@ impl<T> LinkedList<T> {
610610 } ;
611611
612612 mem:: swap ( & mut split_node. resolve ( ) . unwrap ( ) . next , & mut splitted_list. list_head ) ;
613+ splitted_list. list_head . as_mut ( ) . unwrap ( ) . prev = Rawlink :: none ( ) ;
613614 self . list_tail = split_node;
614615 self . length = at;
615616
@@ -1075,6 +1076,26 @@ mod tests {
10751076 }
10761077 }
10771078
1079+ #[ test]
1080+ fn test_26021 ( ) {
1081+ use std:: iter:: ExactSizeIterator ;
1082+ // There was a bug in split_off that failed to null out the RHS's head's prev ptr.
1083+ // This caused the RHS's dtor to walk up into the LHS at drop and delete all of
1084+ // its nodes.
1085+ //
1086+ // https://github.com/rust-lang/rust/issues/26021
1087+ let mut v1 = LinkedList :: new ( ) ;
1088+ v1. push_front ( 1u8 ) ;
1089+ v1. push_front ( 1u8 ) ;
1090+ v1. push_front ( 1u8 ) ;
1091+ v1. push_front ( 1u8 ) ;
1092+ let _ = v1. split_off ( 3 ) ; // Dropping this now should not cause laundry consumption
1093+ assert_eq ! ( v1. len( ) , 3 ) ;
1094+
1095+ assert_eq ! ( v1. iter( ) . len( ) , 3 ) ;
1096+ assert_eq ! ( v1. iter( ) . collect:: <Vec <_>>( ) . len( ) , 3 ) ;
1097+ }
1098+
10781099 #[ cfg( test) ]
10791100 fn fuzz_test ( sz : i32 ) {
10801101 let mut m: LinkedList < _ > = LinkedList :: new ( ) ;
You can’t perform that action at this time.
0 commit comments