diff options
author | Andreas Schwab <schwab@redhat.com> | 2009-07-20 11:02:11 +0200 |
---|---|---|
committer | Andreas Schwab <schwab@redhat.com> | 2009-07-20 11:02:11 +0200 |
commit | 53924a77a2b827e7f9af6424a6a30224d09692d1 (patch) | |
tree | ba5d034a512524339fcfed113518eb83201fdc23 /malloc | |
parent | 8ecde8e8c2a8e77804f954afffd9efe0ab951e52 (diff) | |
parent | 42e69bcf1137fccfd7a95645a9d316c6490b9ff9 (diff) |
Merge commit 'origin/master' into fedora/master
Diffstat (limited to 'malloc')
-rw-r--r-- | malloc/malloc.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c index 516d401991..a459a2b89d 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -4799,8 +4799,29 @@ _int_free(mstate av, mchunkptr p) || __builtin_expect (chunksize (chunk_at_offset (p, size)) >= av->system_mem, 0)) { - errstr = "free(): invalid next size (fast)"; - goto errout; +#ifdef ATOMIC_FASTBINS + /* We might not have a lock at this point and concurrent modifications + of system_mem might have let to a false positive. Redo the test + after getting the lock. */ + if (have_lock + || ({ assert (locked == 0); + mutex_lock(&av->mutex); + locked = 1; + chunk_at_offset (p, size)->size <= 2 * SIZE_SZ + || chunksize (chunk_at_offset (p, size)) >= av->system_mem; + })) +#endif + { + errstr = "free(): invalid next size (fast)"; + goto errout; + } +#ifdef ATOMIC_FASTBINS + if (! have_lock) + { + (void)mutex_unlock(&av->mutex); + locked = 0; + } +#endif } if (__builtin_expect (perturb_byte, 0)) @@ -4823,7 +4844,7 @@ _int_free(mstate av, mchunkptr p) } p->fd = fd = old; } - while ((old = catomic_compare_and_exchange_val_acq (fb, p, fd)) != fd); + while ((old = catomic_compare_and_exchange_val_rel (fb, p, fd)) != fd); #else /* Another simple check: make sure the top of the bin is not the record we are going to add (i.e., double free). */ |