From: Ivan Maidanski Date: Sun, 30 Mar 2014 08:53:48 +0000 (+0400) Subject: Fix out-of-memory case in new_back_edges, push_in_progress (backgraph) X-Git-Tag: gc7_4_2~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc12c339246d10dd42a8e8650223e38aadf2c988;p=gc Fix out-of-memory case in new_back_edges, push_in_progress (backgraph) * 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). --- diff --git a/backgraph.c b/backgraph.c index 5cc85b4a..4b087e43 100644 --- a/backgraph.c +++ b/backgraph.c @@ -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. */ }