3636 yield_on_subject_validation /1 , bad_utf8_subject /1 ,
3737 error_info /1 , subject_is_sub_binary /1 , pattern_is_sub_binary /1 ,
3838 import /1 ,
39+ kill_yielding /1 ,
3940
4041 last_test /1 ]).
4142
@@ -62,6 +63,7 @@ all() ->
6263 yield_on_subject_validation , bad_utf8_subject ,
6364 error_info , subject_is_sub_binary , pattern_is_sub_binary ,
6465 import ,
66+ kill_yielding ,
6567
6668 last_test ].
6769
@@ -1246,7 +1248,29 @@ build_exported(Hdr1, RE, Opts, Enc) ->
12461248 Hdr2 = <<Title /binary , CRC2 :32 , HdrRest /binary >>,
12471249 {re_exported_pattern , Hdr2 , RE , Opts , Enc }.
12481250
1251+ % % OTP-19888: Verify that process can handle being killed while yielding
1252+ % % inside re:run without beam crash or memory leak.
1253+ kill_yielding (Config ) when is_list (Config ) ->
1254+ Subject = binary :copy (~ " hejsan" , 100_000 ),
1255+ DoIt = fun (RE ) ->
1256+ {Pid , MRef } = spawn_monitor (fun () ->
1257+ re :run (Subject , RE )
1258+ end ),
1259+ erlang :yield (),
1260+ exit (Pid , kill ),
1261+ {'DOWN' ,MRef ,process ,Pid ,killed } = receive_any ()
1262+ end ,
1263+
1264+ RE_string = ~B " \w+\d" ,
1265+ {ok , RE_compiled } = re :compile (RE_string , []),
1266+ DoIt (RE_string ),
1267+ DoIt (RE_compiled ),
1268+ ok .
12491269
1270+ receive_any () ->
1271+ receive M -> M
1272+ after 1000 -> timeout
1273+ end .
12501274
12511275last_test (Config ) when is_list (Config ) ->
12521276 erts_debug :set_internal_state (available_internal_state , true ),
0 commit comments