mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-02 17:32:18 +01:00 
			
		
		
		
	gthread: Destroy value after replacing it in g_private_replace()
If the old value is destroyed before updating the TLS value in pthreads (or the Windows equivalent) then there’s a risk of infinite recursion if `g_private_replace()` is called from within the `GDestroyNotify`. Avoid that by destroying the old value after doing the TLS update. Thanks to Matthias Clasen for diagnosing the issue. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2210
This commit is contained in:
		
				
					committed by
					
						
						Christian Hergert
					
				
			
			
				
	
			
			
			
						parent
						
							bacbec652d
						
					
				
				
					commit
					e4af46fc09
				
			@@ -1116,11 +1116,12 @@ g_private_replace (GPrivate *key,
 | 
			
		||||
  gint status;
 | 
			
		||||
 | 
			
		||||
  old = pthread_getspecific (*impl);
 | 
			
		||||
  if (old && key->notify)
 | 
			
		||||
    key->notify (old);
 | 
			
		||||
 | 
			
		||||
  if G_UNLIKELY ((status = pthread_setspecific (*impl, value)) != 0)
 | 
			
		||||
    g_thread_abort (status, "pthread_setspecific");
 | 
			
		||||
 | 
			
		||||
  if (old && key->notify)
 | 
			
		||||
    key->notify (old);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* {{{1 GThread */
 | 
			
		||||
 
 | 
			
		||||
@@ -373,9 +373,9 @@ g_private_replace (GPrivate *key,
 | 
			
		||||
  gpointer old;
 | 
			
		||||
 | 
			
		||||
  old = TlsGetValue (impl);
 | 
			
		||||
  TlsSetValue (impl, value);
 | 
			
		||||
  if (old && key->notify)
 | 
			
		||||
    key->notify (old);
 | 
			
		||||
  TlsSetValue (impl, value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* {{{1 GThread */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user