From ce437b88df500a184ae2ca15d67a019f57a11d20 Mon Sep 17 00:00:00 2001 From: Shailesh Mistry Date: Tue, 28 Feb 2017 18:43:04 +0000 Subject: Bug 697545: Memory Squeezing fix. Fix memory leaks for allocation event numbers 25 to 32 when memory squeezing: gs -sDEVICE=bit -o /dev/null: examples/tiger.eps --- psi/imain.c | 25 +++++++++++++++---------- psi/iname.c | 15 ++++++++++++--- psi/inames.h | 3 +++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/psi/imain.c b/psi/imain.c index 31872c971..9aca7dcda 100644 --- a/psi/imain.c +++ b/psi/imain.c @@ -181,22 +181,23 @@ gs_main_init0(gs_main_instance * minst, FILE * in, FILE * out, FILE * err, int gs_main_init1(gs_main_instance * minst) { + gs_dual_memory_t idmem; + name_table *nt = NULL; + int code = 0; + if (minst->init_done < 1) { - gs_dual_memory_t idmem; - int code = - ialloc_init(&idmem, minst->heap, + code = ialloc_init(&idmem, minst->heap, minst->memory_clump_size, gs_have_level2()); if (code < 0) return code; code = gs_lib_init1((gs_memory_t *)idmem.space_system); if (code < 0) - return code; + goto fail; alloc_save_init(&idmem); { gs_memory_t *mem = (gs_memory_t *)idmem.space_system; - name_table *nt = names_init(minst->name_table_size, - idmem.space_system); + nt = names_init(minst->name_table_size, idmem.space_system); if (nt == 0) return_error(gs_error_VMerror); @@ -205,21 +206,25 @@ gs_main_init1(gs_main_instance * minst) (void **)&mem->gs_lib_ctx->gs_name_table, "the_gs_name_table"); if (code < 0) - return code; + goto fail; mem->gs_lib_ctx->client_check_file_permission = z_check_file_permissions; } code = obj_init(&minst->i_ctx_p, &idmem); /* requires name_init */ if (code < 0) - return code; + goto fail; code = i_plugin_init(minst->i_ctx_p); if (code < 0) - return code; + goto fail; code = i_iodev_init(minst->i_ctx_p); if (code < 0) - return code; + goto fail; minst->init_done = 1; } return 0; + +fail: + names_free(nt); + return code; } /* diff --git a/psi/iname.c b/psi/iname.c index 88cc938fe..a2e234924 100644 --- a/psi/iname.c +++ b/psi/iname.c @@ -102,9 +102,7 @@ names_init(ulong count, gs_ref_memory_t *imem) int code = name_alloc_sub(nt); if (code < 0) { - while (nt->sub_next > 0) - name_free_sub(nt, --(nt->sub_next), false); - gs_free_object(mem, nt, "name_init(nt)"); + names_free(nt); return 0; } } @@ -131,6 +129,17 @@ names_init(ulong count, gs_ref_memory_t *imem) return nt; } +/* Free a name table */ +void +names_free(name_table *nt) +{ + if (nt == NULL) return; + + while (nt->sub_count > 0) + name_free_sub(nt, --(nt->sub_count), false); + gs_free_object(nt->memory, nt, "name_init(nt)"); +} + static void gs_names_finalize(const gs_memory_t *cmem, void *vptr) { diff --git a/psi/inames.h b/psi/inames.h index a1b5dff57..9d55e5505 100644 --- a/psi/inames.h +++ b/psi/inames.h @@ -48,6 +48,9 @@ typedef struct gs_ref_memory_s gs_ref_memory_t; /* Allocate and initialize a name table. */ name_table *names_init(ulong size, gs_ref_memory_t *imem); +/* Free a name table */ +void names_free(name_table *nt); + /* Get the allocator for a name table. */ gs_memory_t *names_memory(const name_table * nt); -- cgit v1.2.1