summaryrefslogtreecommitdiff
path: root/headers.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2021-09-22 08:45:46 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-09-22 08:45:46 +0300
commitc122325eb49cde7974198a57bcb470f057c9e5fb (patch)
tree63efbcecf0d84e2c1698865a5b032dec2e42964d /headers.c
parentffb9f1e82d6a95c3bc16df5089c5f8f9c084dc95 (diff)
downloadbdwgc-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.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/headers.c b/headers.c
index 25524176..d2d3da8a 100644
--- a/headers.c
+++ b/headers.c
@@ -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;