From fde97b79c8681ef27bd731ef42766589ce892e66 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 22 Dec 2016 11:05:41 +0300 Subject: Eliminate 'memory leak' code defect for scratch-allocated memory Reuse memory allocated by GC_scratch_alloc and GET_MEM in GC heap if possible. * backgraph.c (push_in_progress): Replace in_progress_size==0 with in_progress_space==NULL (to ensure BCOPY argument is non-NULL); eliminate code duplication regarding GC_add_to_our_memory call; call GC_scratch_recycle_no_gww (for old in_progress_space value) unless GWW_VDB (and remove corresponding FIXME). * dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX] (GC_register_dynamic_libraries): Call GC_scratch_recycle_no_gww (for old addr_map and current_sz values). * include/private/gc_priv.h [!GWW_VDB] (GC_scratch_recycle_no_gww): New internal macro. * include/private/gc_priv.h (GC_scratch_recycle_inner): New prototype. * mark.c (GC_scratch_recycle_inner): New function (move code portion from alloc_mark_stack). * mark.c (alloc_mark_stack): Call GC_scratch_recycle_inner (if recycle_old). * os_dep.c [NEED_PROC_MAPS] (GC_get_maps): Call GC_scratch_recycle_no_gww (for old maps_buf and maps_buf_sz values). * os_dep.c [PROC_VDB] (GC_read_dirty): Call GC_scratch_recycle_no_gww (for old GC_proc_buf and GC_proc_buf_size values). --- dyn_load.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'dyn_load.c') diff --git a/dyn_load.c b/dyn_load.c index dbc145dc..beda2b8d 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -816,6 +816,8 @@ GC_INNER void GC_register_dynamic_libraries(void) ": fd = %d, errno = %d", fd, errno); } if (needed_sz >= current_sz) { + GC_scratch_recycle_no_gww(addr_map, + (size_t)current_sz * sizeof(prmap_t)); current_sz = needed_sz * 2 + 1; /* Expansion, plus room for 0 record */ addr_map = (prmap_t *)GC_scratch_alloc( -- cgit v1.2.1