From fc12c339246d10dd42a8e8650223e38aadf2c988 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sun, 30 Mar 2014 12:53:48 +0400 Subject: [PATCH] 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). --- backgraph.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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. */ } -- 2.40.0