diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2021-09-22 08:45:46 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-09-22 08:45:46 +0300 |
commit | c122325eb49cde7974198a57bcb470f057c9e5fb (patch) | |
tree | 63efbcecf0d84e2c1698865a5b032dec2e42964d /headers.c | |
parent | ffb9f1e82d6a95c3bc16df5089c5f8f9c084dc95 (diff) | |
download | bdwgc-c122325eb49cde7974198a57bcb470f057c9e5fb.tar.gz |
Do not call add_to_our_memory with null pointer
(refactoring)
* alloc.c [USE_PROC_FOR_LIBRARIES] (GC_add_to_our_memory): Do not
accept p == NULL (add assertion about it).
* alloc.c (GC_expand_hp_inner): Call GC_add_to_our_memory() only if
the pointer is non-NULL; Use EXPECT() to check the pointer.
* backgraph.c [MAKE_BACK_GRAPH] (push_in_progress): Likewise.
* headers.c (GC_scratch_alloc): Likewise.
* include/private/gc_priv.h [USE_PROC_FOR_LIBRARIES]
(GC_add_to_our_memory): Remove comment that p could be NULL.
* include/private/gc_priv.h [!USE_PROC_FOR_LIBRARIES]
(GC_add_to_our_memory): Cast p and bytes to void.
Diffstat (limited to 'headers.c')
-rw-r--r-- | headers.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -120,34 +120,37 @@ GC_INNER ptr_t GC_scratch_alloc(size_t bytes) if (bytes >= MINHINCR * HBLKSIZE) { bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes); result = (ptr_t)GET_MEM(bytes_to_get); - GC_add_to_our_memory(result, bytes_to_get); - /* No update of scratch free area pointer; get memory directly. */ -# ifdef USE_SCRATCH_LAST_END_PTR - if (result != NULL) { + if (result != NULL) { + GC_add_to_our_memory(result, bytes_to_get); + /* No update of scratch free area pointer; */ + /* get memory directly. */ +# ifdef USE_SCRATCH_LAST_END_PTR /* Update end point of last obtained area (needed only */ /* by GC_register_dynamic_libraries for some targets). */ GC_scratch_last_end_ptr = result + bytes; - } -# endif +# endif + } return result; } bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(MINHINCR * HBLKSIZE); /* round up for safety */ result = (ptr_t)GET_MEM(bytes_to_get); - GC_add_to_our_memory(result, bytes_to_get); - if (NULL == result) { + if (EXPECT(NULL == result, FALSE)) { WARN("Out of memory - trying to allocate requested amount" " (%" WARN_PRIdPTR " bytes)...\n", (word)bytes); bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes); result = (ptr_t)GET_MEM(bytes_to_get); - GC_add_to_our_memory(result, bytes_to_get); -# ifdef USE_SCRATCH_LAST_END_PTR - if (result != NULL) + if (result != NULL) { + GC_add_to_our_memory(result, bytes_to_get); +# ifdef USE_SCRATCH_LAST_END_PTR GC_scratch_last_end_ptr = result + bytes; -# endif +# endif + } return result; } + + GC_add_to_our_memory(result, bytes_to_get); /* TODO: some amount of unallocated space may remain unused forever */ /* Update scratch area pointers and retry. */ GC_scratch_free_ptr = result; |