]> granicus.if.org Git - gc/commitdiff
Fix out-of-memory case in new_back_edges, push_in_progress (backgraph)
authorIvan Maidanski <ivmai@mail.ru>
Sun, 30 Mar 2014 08:53:48 +0000 (12:53 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 2 May 2014 20:33:17 +0000 (00:33 +0400)
* backgraph.c (new_back_edges): Abort if not enough memory.
* backgraph.c (push_in_progress): Prevent null pointer dereference in
BCOPY() if allocation failed (due to not enough memory).

backgraph.c

index 5cc85b4a098663dff4bafecac9859c04aa44f759..4b087e43dca9175fab4d3808aeb584df8070b973 100644 (file)
@@ -89,6 +89,8 @@ static back_edges * new_back_edges(void)
     back_edge_space = (back_edges *)GET_MEM(
                         ROUNDUP_PAGESIZE_IF_MMAP(MAX_BACK_EDGE_STRUCTS
                                                   * sizeof(back_edges)));
+    if (NULL == back_edge_space)
+      ABORT("Insufficient memory for back edges");
     GC_add_to_our_memory((ptr_t)back_edge_space,
                          MAX_BACK_EDGE_STRUCTS*sizeof(back_edges));
   }
@@ -141,8 +143,9 @@ static void push_in_progress(ptr_t p)
                                 GET_MEM(in_progress_size * sizeof(ptr_t));
       GC_add_to_our_memory((ptr_t)new_in_progress_space,
                            in_progress_size * sizeof(ptr_t));
-      BCOPY(in_progress_space, new_in_progress_space,
-            n_in_progress * sizeof(ptr_t));
+      if (new_in_progress_space != NULL)
+        BCOPY(in_progress_space, new_in_progress_space,
+              n_in_progress * sizeof(ptr_t));
       in_progress_space = new_in_progress_space;
       /* FIXME: This just drops the old space.  */
     }