@@ -1348,7 +1348,7 @@ fn spawn_pty_shell(
13481348 #[ cfg( target_os = "linux" ) ]
13491349 let child_pid = child. id ( ) ;
13501350 #[ cfg( target_os = "linux" ) ]
1351- managed_children:: register ( child_pid) ;
1351+ let managed_child = managed_children:: register ( child_pid) ;
13521352 let master_file = master;
13531353
13541354 let ( sender, receiver) = mpsc:: channel :: < Vec < u8 > > ( ) ;
@@ -1394,7 +1394,9 @@ fn spawn_pty_shell(
13941394 std:: thread:: spawn ( move || {
13951395 let status = child. wait ( ) . ok ( ) ;
13961396 #[ cfg( target_os = "linux" ) ]
1397- managed_children:: unregister ( child_pid) ;
1397+ if let Some ( child) = managed_child {
1398+ managed_children:: unregister ( child) ;
1399+ }
13981400 let code = status. and_then ( |s| s. code ( ) ) . unwrap_or ( 1 ) . unsigned_abs ( ) ;
13991401 // Wait for the reader thread to finish forwarding all output before
14001402 // sending exit-status and closing the channel. This prevents the
@@ -1507,7 +1509,7 @@ fn spawn_pipe_exec(
15071509 #[ cfg( target_os = "linux" ) ]
15081510 let child_pid = child. id ( ) ;
15091511 #[ cfg( target_os = "linux" ) ]
1510- managed_children:: register ( child_pid) ;
1512+ let managed_child = managed_children:: register ( child_pid) ;
15111513
15121514 let child_stdin = child. stdin . take ( ) ;
15131515 let child_stdout = child. stdout . take ( ) . expect ( "stdout must be piped" ) ;
@@ -1579,7 +1581,9 @@ fn spawn_pipe_exec(
15791581 std:: thread:: spawn ( move || {
15801582 let status = child. wait ( ) . ok ( ) ;
15811583 #[ cfg( target_os = "linux" ) ]
1582- managed_children:: unregister ( child_pid) ;
1584+ if let Some ( child) = managed_child {
1585+ managed_children:: unregister ( child) ;
1586+ }
15831587 let code = status. and_then ( |s| s. code ( ) ) . unwrap_or ( 1 ) . unsigned_abs ( ) ;
15841588 // Wait for both reader threads.
15851589 let _ = reader_done_rx. recv_timeout ( Duration :: from_secs ( 2 ) ) ;
0 commit comments