mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	bpo-39877: Fix take_gil() for daemon threads (GH-19054)
bpo-39877, bpo-39984: If the thread must exit, don't access tstate to prevent a potential crash: tstate memory has been freed.
This commit is contained in:
		
							parent
							
								
									23ef89db7a
								
							
						
					
					
						commit
						29356e03d4
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -281,13 +281,17 @@ take_gil(PyThreadState *tstate)
 | 
				
			||||||
    if (_Py_atomic_load_relaxed(&ceval->gil_drop_request)) {
 | 
					    if (_Py_atomic_load_relaxed(&ceval->gil_drop_request)) {
 | 
				
			||||||
        RESET_GIL_DROP_REQUEST(ceval);
 | 
					        RESET_GIL_DROP_REQUEST(ceval);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (tstate->async_exc != NULL) {
 | 
					
 | 
				
			||||||
 | 
					    int must_exit = tstate_must_exit(tstate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Don't access tstate if the thread must exit */
 | 
				
			||||||
 | 
					    if (!must_exit && tstate->async_exc != NULL) {
 | 
				
			||||||
        _PyEval_SignalAsyncExc(ceval);
 | 
					        _PyEval_SignalAsyncExc(ceval);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MUTEX_UNLOCK(gil->mutex);
 | 
					    MUTEX_UNLOCK(gil->mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (tstate_must_exit(tstate)) {
 | 
					    if (must_exit) {
 | 
				
			||||||
        /* bpo-36475: If Py_Finalize() has been called and tstate is not
 | 
					        /* bpo-36475: If Py_Finalize() has been called and tstate is not
 | 
				
			||||||
           the thread which called Py_Finalize(), exit immediately the
 | 
					           the thread which called Py_Finalize(), exit immediately the
 | 
				
			||||||
           thread.
 | 
					           thread.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue