[PATCH 4/5] Fix deadlock in _int_free consistency check
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Thu Oct 12 21:35:00 GMT 2017
DJ Delorie wrote:
> I think the bug can be fixed by only changing the sense of the have_lock
> condition:
> - if (!have_lock
> + if (have_lock
Yes it could but then it's still impossible to follow the logic... The only reason
I spotted the bug was because I refactored the code. Then the bug suddenly
became very obvious. I think locking as a side effect in conditions is something
we should avoid.
So my variant or this one are reasonable ways to do it:
if (error detected)
{
if (have_lock)
/* we had the lock during the test above, so the test is valid,
and the error we detect is valid. */
print error message
else
/* we didn't have the lock, so aquire it and repeat the test. If
the error is still present, fail. */
get lock, repeat test, maybe print error message
}
I suppose we could also print the error once at the end:
if (error detected)
{
bool fail = true;
if (!have_lock)
{
get_lock
fail = repeat test
unlock
}
if (fail)
print error
}
Wilco
More information about the Libc-alpha
mailing list