diff options
author | Benjamin Berg <bberg@redhat.com> | 2021-07-24 14:20:55 +0200 |
---|---|---|
committer | Marco Trevisan <mail@3v1n0.net> | 2021-07-26 13:09:13 +0000 |
commit | 161278cacd36706430b6b2e527436eb972122de9 (patch) | |
tree | 3f70a8d281f453156c6764fe9ce2b7ef7dd18f72 | |
parent | 2dd1cd8fc3625b7295b1953fa5fe2c0871d917e9 (diff) |
device: Add a memory barrier when getting session pointer
The test suite ran into a very rare error where it seemed to get stuck
during authorization. A possible explanation is that the priv->_session
pointer re-fetching is optimized away and the pointer just continues to
contain the invalid placeholder rather than an updated value.
Use g_atomic_pointer_get in order to avoid this possibility entirely.
-rw-r--r-- | src/device.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/device.c b/src/device.c index 49cbdd5..155f659 100644 --- a/src/device.c +++ b/src/device.c @@ -168,7 +168,7 @@ session_data_get (FprintDevicePrivate *priv) /* Get the current pointer and mark the pointer as "busy". */ do { - cur = priv->_session; + cur = g_atomic_pointer_get (&priv->_session); /* Swap if cur is valid, otherwise busy loop. */ } while (cur == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, cur, invalid)); @@ -205,7 +205,7 @@ session_data_set_new (FprintDevicePrivate *priv, gchar *sender, gchar *username) /* Get the current (but not if it is busy) and put the new one in place. */ do { - old = priv->_session; + old = g_atomic_pointer_get (&priv->_session); /* Swap if old is valid, otherwise busy loop as someone is ref'ing it currently. */ } while (old == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, old, new)); |