]> granicus.if.org Git - gc/commitdiff
Fix GC_out_of_line_malloc in new_gc_alloc.h for out-of-memory case
authorIvan Maidanski <ivmai@mail.ru>
Thu, 24 May 2018 22:08:25 +0000 (01:08 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 24 May 2018 22:08:25 +0000 (01:08 +0300)
* include/new_gc_alloc.h (GC_out_of_line_malloc): Call
GC_generic_malloc_words_small() before the counters update; do not
update the counters if GC_generic_malloc_words_small() returns 0.

include/new_gc_alloc.h

index 866136b4486a386e0bae164ffeb11b4a81966990..5d459ee4935a2a7c13705f2b73de148c9c65a1f8 100644 (file)
@@ -148,6 +148,9 @@ size_t GC_aux_template<dummy>::GC_uncollectable_bytes_recently_freed = 0;
 template <int dummy>
 void * GC_aux_template<dummy>::GC_out_of_line_malloc(size_t nwords, int kind)
 {
+    void * op = GC_generic_malloc_words_small(nwords, kind);
+    if (!op) return 0;
+
     GC_bytes_recently_allocd += GC_uncollectable_bytes_recently_allocd;
     GC_non_gc_bytes +=
                 GC_uncollectable_bytes_recently_allocd;
@@ -162,8 +165,7 @@ void * GC_aux_template<dummy>::GC_out_of_line_malloc(size_t nwords, int kind)
 
     GC_incr_bytes_freed(GC_bytes_recently_freed);
     GC_bytes_recently_freed = 0;
-
-    return GC_generic_malloc_words_small(nwords, kind);
+    return op;
 }
 
 typedef GC_aux_template<0> GC_aux;