]> granicus.if.org Git - gc/commitdiff
Ensure oom_fn callback executed on out-of-memory in calloc
authorIvan Maidanski <ivmai@mail.ru>
Fri, 18 Nov 2016 14:16:32 +0000 (17:16 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 18 Nov 2016 14:16:32 +0000 (17:16 +0300)
(fix commits e10c1eb4e1a6f9)

* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc):
Call oom_fn(SIZE_MAX) (instead of returning NULL) if n*lb overflows.
* typd_mlc.c (GC_calloc_explicitly_typed): Likewise.
* typd_mlc.c (GC_calloc_explicitly_typed): If register_disappearing_link
failed due to lack of memory then call oom_fn(lb) instead of
GC_malloc(lb); update comment.

malloc.c
typd_mlc.c

index c4a5430665af0e46ad837100dea071b027638704..5301518c9fde00d194b71612e8e7c4273442038d 100644 (file)
--- a/malloc.c
+++ b/malloc.c
@@ -431,7 +431,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_uncollectable(size_t lb)
   {
     if ((lb | n) > GC_SQRT_SIZE_MAX /* fast initial test */
         && lb && n > GC_SIZE_MAX / lb)
-      return NULL;
+      return (*GC_get_oom_fn())(GC_SIZE_MAX); /* n*lb overflow */
 #   if defined(GC_LINUX_THREADS)
       /* libpthread allocated some memory that is only pointed to by    */
       /* mmapped thread stacks.  Make sure it is not collectible.       */
index d19e4c11e204f614e08a6209464c03b0cf2d3bd8..7e91fab230db2a48f6d83898c73ee05c248eafc1 100644 (file)
@@ -647,7 +647,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_calloc_explicitly_typed(size_t n,
                                           &complex_descr, &leaf);
     if ((lb | n) > GC_SQRT_SIZE_MAX /* fast initial check */
         && lb > 0 && n > GC_SIZE_MAX / lb)
-      return NULL; /* n*lb overflow */
+      return (*GC_get_oom_fn())(GC_SIZE_MAX); /* n*lb overflow */
     lb *= n;
     switch(descr_type) {
         case NO_MEM: return(0);
@@ -690,9 +690,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_calloc_explicitly_typed(size_t n,
 #     endif
         {
             /* Couldn't register it due to lack of memory.  Punt.       */
-            /* This will probably fail too, but gives the recovery code */
-            /* a chance.                                                */
-            return GC_malloc(lb);
+            return (*GC_get_oom_fn())(lb);
         }
     }
     return op;