mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 13:00:06 +00:00
Fix wrap-around in memusage.
This commit is contained in:
parent
d94760f944
commit
22bc5239e1
@ -1,3 +1,8 @@
|
|||||||
|
2009-10-29 Andreas Schwab <schwab@redhat.com>
|
||||||
|
|
||||||
|
* malloc/memusage.c (update_data): Fix index wraparound handling
|
||||||
|
so that buffer_cnt is actually reset.
|
||||||
|
|
||||||
2009-10-29 Ulrich Drepper <drepper@redhat.com>
|
2009-10-29 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
[BZ #10784]
|
[BZ #10784]
|
||||||
|
@ -163,15 +163,16 @@ update_data (struct header *result, size_t len, size_t old_len)
|
|||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
uatomic32_t idx = catomic_exchange_and_add (&buffer_cnt, 1);
|
uatomic32_t idx = catomic_exchange_and_add (&buffer_cnt, 1);
|
||||||
if (idx >= 2 * buffer_size)
|
if (idx + 1 >= 2 * buffer_size)
|
||||||
{
|
{
|
||||||
/* We try to reset the counter to the correct range. If
|
/* We try to reset the counter to the correct range. If
|
||||||
this fails because of another thread increasing the
|
this fails because of another thread increasing the
|
||||||
counter it does not matter since that thread will take
|
counter it does not matter since that thread will take
|
||||||
care of the correction. */
|
care of the correction. */
|
||||||
uatomic32_t reset = idx % (2 * buffer_size);
|
uatomic32_t reset = (idx + 1) % (2 * buffer_size);
|
||||||
catomic_compare_and_exchange_val_acq (&buffer_cnt, reset, idx);
|
catomic_compare_and_exchange_val_acq (&buffer_cnt, reset, idx + 1);
|
||||||
idx = reset;
|
if (idx >= 2 * buffer_size)
|
||||||
|
idx = reset - 1;
|
||||||
}
|
}
|
||||||
assert (idx < 2 * DEFAULT_BUFFER_SIZE);
|
assert (idx < 2 * DEFAULT_BUFFER_SIZE);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user