summaryrefslogtreecommitdiff
path: root/libc/malloc/malloc.c
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2009-07-29 15:58:14 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2009-07-29 15:58:14 +0000
commit4d6da0374a6f9e36702cb9fbc7418d144cd62410 (patch)
tree2bb034af8c0fbf06bc06b9e485e17ae16cdd1b8a /libc/malloc/malloc.c
parentdccd0f1fe606c19588c65468c90060350f5d368b (diff)
Merge changes between r8623 and r8721 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@8722 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/malloc/malloc.c')
-rw-r--r--libc/malloc/malloc.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/libc/malloc/malloc.c b/libc/malloc/malloc.c
index 516d40199..a459a2b89 100644
--- a/libc/malloc/malloc.c
+++ b/libc/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). */