Fix data race in multithreaded application

This commit fixes a data race condition discovered by the
gcc thread sanitizer by also locking the associated mutex
when reading the corresponding counter.

Fixes #426
This commit is contained in:
Ralf Habacker 2023-01-03 14:29:14 +01:00
parent 20febb522b
commit 1741df3b97
1 changed files with 10 additions and 2 deletions

View File

@ -275,7 +275,11 @@ _dbus_counter_adjust_unix_fd (DBusCounter *counter,
long
_dbus_counter_get_size_value (DBusCounter *counter)
{
return counter->size_value;
long result;
_dbus_rmutex_lock (counter->mutex);
result = counter->size_value;
_dbus_rmutex_unlock (counter->mutex);
return result;
}
/**
@ -287,7 +291,11 @@ _dbus_counter_get_size_value (DBusCounter *counter)
long
_dbus_counter_get_unix_fd_value (DBusCounter *counter)
{
return counter->unix_fd_value;
long result;
_dbus_rmutex_lock (counter->mutex);
result = counter->unix_fd_value;
_dbus_rmutex_unlock (counter->mutex);
return result;
}
/**