mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Restart timer thread even after preparation failed
If the timer thread is left stopped, memory crash or segfault can happen. [Bug #16624]
This commit is contained in:
		
							parent
							
								
									9c07f803db
								
							
						
					
					
						commit
						95ab9cd8f4
					
				
					 2 changed files with 18 additions and 2 deletions
				
			
		
							
								
								
									
										11
									
								
								process.c
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								process.c
									
										
									
									
									
								
							|  | @ -2885,13 +2885,20 @@ rb_f_exec(int argc, const VALUE *argv) | |||
|     struct rb_execarg *eargp; | ||||
| #define CHILD_ERRMSG_BUFLEN 80 | ||||
|     char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' }; | ||||
|     int err; | ||||
|     int err, state; | ||||
| 
 | ||||
|     execarg_obj = rb_execarg_new(argc, argv, TRUE, FALSE); | ||||
|     eargp = rb_execarg_get(execarg_obj); | ||||
|     if (mjit_enabled) mjit_finish(false); // avoid leaking resources, and do not leave files. XXX: JIT-ed handle can leak after exec error is rescued.
 | ||||
|     before_exec(); /* stop timer thread before redirects */ | ||||
|     rb_execarg_parent_start(execarg_obj); | ||||
| 
 | ||||
|     rb_protect(rb_execarg_parent_start1, execarg_obj, &state); | ||||
|     if (state) { | ||||
|         execarg_parent_end(execarg_obj); | ||||
|         after_exec(); /* restart timer thread */ | ||||
|         rb_jump_tag(state); | ||||
|     } | ||||
| 
 | ||||
|     fail_str = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name; | ||||
| 
 | ||||
|     err = exec_async_signal_safe(eargp, errmsg, sizeof(errmsg)); | ||||
|  |  | |||
|  | @ -2399,6 +2399,15 @@ EOS | |||
|     r.close if r | ||||
|   end if defined?(fork) | ||||
| 
 | ||||
|   def test_rescue_exec_fail | ||||
|     assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") | ||||
|     begin; | ||||
|       assert_raise(Errno::ENOENT) do | ||||
|         exec("", in: "") | ||||
|       end | ||||
|     end; | ||||
|   end | ||||
| 
 | ||||
|   def test_many_args | ||||
|     bug11418 = '[ruby-core:70251] [Bug #11418]' | ||||
|     assert_in_out_err([], <<-"end;", ["x"]*256, [], bug11418, timeout: 60) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nobuyoshi Nakada
						Nobuyoshi Nakada