From 161278cacd36706430b6b2e527436eb972122de9 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Sat, 24 Jul 2021 14:20:55 +0200 Subject: [PATCH] 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. --- src/device.c | 4 ++-- 1 file 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));