diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2022-01-13 16:54:02 +0000 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2022-01-13 23:51:24 +0000 |
commit | e039a404e7796d0435fa6f63b6f182ec59c14051 (patch) | |
tree | af52a6f5092aed5be893d38701c3e80fe94b90f6 | |
parent | 9c4eb789379cfd0902a4e4981d101d11fc7b01a4 (diff) | |
download | ghostpdl-e039a404e7796d0435fa6f63b6f182ec59c14051.tar.gz |
Fix some memory leaks with gpcl6.
When a memento build of gpcl6 is run with no arguments, we can
see that memory leaks. Here we fix some of those.
Firstly, free the font directory.
Secondly, free the paper type table.
-rw-r--r-- | base/gsfont.c | 7 | ||||
-rw-r--r-- | base/gsfont.h | 1 | ||||
-rw-r--r-- | pcl/pcl/pcpalet.c | 4 | ||||
-rw-r--r-- | pcl/pcl/pctop.c | 19 |
4 files changed, 30 insertions, 1 deletions
diff --git a/base/gsfont.c b/base/gsfont.c index d31841277..6bc88dc19 100644 --- a/base/gsfont.c +++ b/base/gsfont.c @@ -322,6 +322,13 @@ gs_font_dir_finalize(const gs_memory_t *cmem, void *vptr) } pdir->ccache.chunks = NULL; } +void +gs_font_dir_free(gs_font_dir *dir) +{ + if (dir == NULL) + return; + gs_free_object(dir->memory, dir, "gs_font_dir_free"); +} /* Allocate and minimally initialize a font. */ gs_font * diff --git a/base/gsfont.h b/base/gsfont.h index a2bfe2721..926c61d33 100644 --- a/base/gsfont.h +++ b/base/gsfont.h @@ -43,6 +43,7 @@ gs_font_dir *gs_font_dir_alloc2_limits(gs_memory_t * struct_mem, gs_memory_t * bits_mem, uint smax, uint bmax, uint mmax, uint cmax, uint upper); +void gs_font_dir_free(gs_font_dir *dir); /* Backward compatibility */ #define gs_font_dir_alloc(mem) gs_font_dir_alloc2(mem, mem) diff --git a/pcl/pcl/pcpalet.c b/pcl/pcl/pcpalet.c index 9d8363f62..554e2851f 100644 --- a/pcl/pcl/pcpalet.c +++ b/pcl/pcl/pcpalet.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -70,6 +70,8 @@ pcl_free_default_objects(gs_memory_t * mem, pcl_state_t * pcs) gs_free_object(mem, ppalette, "free_default_palette ppalette free"); pcs->pdflt_palette = 0; } + rc_decrement(pcs->pfrgrnd, "free foreground"); + rc_decrement(pcs->pdflt_frgrnd, "free default foreground"); /* what on earth is this? */ rc_decrement(pcs->pdflt_ht, "free_default_palette pdflt_ht release"); rc_decrement(pcs->pdflt_ht, "free_default_palette pdflt_ht release"); diff --git a/pcl/pcl/pctop.c b/pcl/pcl/pctop.c index f9f16a577..f953e1f47 100644 --- a/pcl/pcl/pctop.c +++ b/pcl/pcl/pctop.c @@ -556,9 +556,16 @@ pcl_impl_deallocate_interp_instance(pl_interp_implementation_t * impl /* ins pcli->pst.hpgl_parser_state, "pcl_deallocate_interp_instance(pcl_interp_instance_t)"); + pl_dict_release(&pcli->pcs.palette_store); + /* free default, pdflt_* objects */ pcl_free_default_objects(mem, &pcli->pcs); + if (pcli->pcs.ppaper_type_table) { + gs_free_object(pcli->pcs.memory, pcli->pcs.ppaper_type_table, "Paper Table"); + pcli->pcs.ppaper_type_table = 0; + } + /* Restore the gstate once, to match the extra 'gsave' done in * pcl_impl_allocate_interp_instance. */ gs_grestore_only(pcli->pcs.pgs); @@ -567,6 +574,18 @@ pcl_impl_deallocate_interp_instance(pl_interp_implementation_t * impl /* ins gs_gstate_free(pcli->pcs.pgs); /* remove pcl's gsave grestore stack */ pcl_free_gstate_stk(&pcli->pcs); + + /* Release font dictionaries. */ + pl_dict_release(&pcli->pcs.soft_symbol_sets); + pl_dict_release(&pcli->pcs.built_in_symbol_sets); + pl_dict_release(&pcli->pcs.simm_fonts); + pl_dict_release(&pcli->pcs.cartridge_fonts); + pl_dict_release(&pcli->pcs.soft_fonts); + pl_dict_release(&pcli->pcs.built_in_fonts); + + gs_font_dir_free(pcli->pcs.font_dir); + + gx_path_free(&pcli->pcs.g.polygon.buffer.path, "pcl_deallocate_interp_instance"); gs_free_object(mem, pcli, "pcl_deallocate_interp_instance(pcl_interp_instance_t)"); return 0; |