IIOD: Fix race introduced in ba6170e7
IIOD: Fix race introduced in ba6170e7

One of the fixes present in this previous commit also introduced
a race condition, which went under the radar as it is much less
likely to happen.

The fix was to lock the DevEntry's thdlist mutex before freeing
a ThdEntry, to ensure that the read thread is done using it.

However, between the moment when the thread was signaled and when
it tried to lock the thdlist mutex, the read thread could exit, if
it had no more clients for instance; and in the process, free its
DevEntry structure and the thdlist mutex it contains.

The real fix introduced in this commit removes the lock on the
thdlist mutex before freeing the ThdEntry. Instead, it makes sure
that the read thread will never access the "thd" structure from
the moment when the thread is signaled.

Signed-off-by: Paul Cercueil <73d292422978d45c9eeef455bb1b24a0db453722@analog.com>

sensarliar/libiio,Sunderfield/libiio,gburca/libiio,analogdevicesinc/libiio,analogdevicesinc/libiio,analogdevicesinc/libiio,Sunderfield/libiio,analogdevicesinc/libiio,sensarliar/libiio,sensarliar/libiio,Sunderfield/libiio,gburca/libiio,gburca/libiio