mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
glib-aux: fix atomic pattern in nm_ref_string_unref()
It's simply not valid to read the ref-count without an atomic.
The compiler might optimize out the assignment to "r" and read the
_ref_count field multiple times. Thereby, we might at first appear
to be larger than > 1, and later pass 1 to compare-and-exchange.
We need an atomic get here.
Fixes: 19d4027824
('refstr: inline nm_ref_string_{ref,unref}()')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1847
This commit is contained in:
parent
d1d96de3a1
commit
5f7a027f59
|
@ -83,7 +83,8 @@ nm_ref_string_unref(NMRefString *rstr)
|
|||
|
||||
/* fast-path: first try to decrement the ref-count without bringing it
|
||||
* to zero. */
|
||||
r = rstr->_ref_count;
|
||||
r = g_atomic_int_get(&rstr->_ref_count);
|
||||
|
||||
if (G_LIKELY(r > 1 && g_atomic_int_compare_and_exchange(&rstr->_ref_count, r, r - 1)))
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in a new issue