summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-03-24 23:07:03 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-03-24 23:07:03 +0300
commit55dbba223f8790e07ab83a1ced9a17fe99f9ed00 (patch)
treee3818d18a2cf1149d84ce3a1e88b13a14ba1d3a3 /malloc.c
parent4f18441368365d056d23ca62efdc7d9920971893 (diff)
downloadbdwgc-55dbba223f8790e07ab83a1ced9a17fe99f9ed00.tar.gz
Do not double-clear first two words of object in GC_generic_malloc_aligned
The beginning of the allocated object is cleared while holding the allocation lock. * malloc.c [!THREADS] (GC_generic_malloc_aligned): If init then call BZERO() before UNLOCK() line (not after). * malloc.c [THREADS]: Do not clear (again) the first 2 words by BZERO() when not holding the lock; add comment.
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/malloc.c b/malloc.c
index b1a14778..b104b11e 100644
--- a/malloc.c
+++ b/malloc.c
@@ -241,7 +241,11 @@ GC_INNER void * GC_generic_malloc_aligned(size_t lb, int k, unsigned flags,
LOCK();
result = GC_alloc_large(lb_rounded, k, flags, align_m1);
if (EXPECT(result != NULL, TRUE)) {
- if (GC_debugging_started) {
+ if (GC_debugging_started
+# ifndef THREADS
+ || init
+# endif
+ ) {
BZERO(result, HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb_rounded));
} else {
# ifdef THREADS
@@ -256,9 +260,13 @@ GC_INNER void * GC_generic_malloc_aligned(size_t lb, int k, unsigned flags,
}
}
UNLOCK();
- if (init && !GC_debugging_started && 0 != result) {
- BZERO(result, HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb_rounded));
- }
+# ifdef THREADS
+ if (init && !GC_debugging_started && result != NULL) {
+ /* Clear the rest (i.e. excluding the initial 2 words). */
+ BZERO((word *)result + 2,
+ HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb_rounded) - 2 * sizeof(word));
+ }
+# endif
}
if (EXPECT(NULL == result, FALSE))
result = (*GC_get_oom_fn())(lb); /* might be misaligned */