diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-03-24 23:07:03 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-03-24 23:07:03 +0300 |
commit | 55dbba223f8790e07ab83a1ced9a17fe99f9ed00 (patch) | |
tree | e3818d18a2cf1149d84ce3a1e88b13a14ba1d3a3 /malloc.c | |
parent | 4f18441368365d056d23ca62efdc7d9920971893 (diff) | |
download | bdwgc-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.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -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 */ |