diff options
-rw-r--r-- | base/gscdevn.c | 4 | ||||
-rw-r--r-- | base/gscolor2.c | 4 | ||||
-rw-r--r-- | base/gscscie.c | 52 | ||||
-rw-r--r-- | base/gscsepr.c | 4 | ||||
-rw-r--r-- | base/gscspace.c | 9 | ||||
-rw-r--r-- | base/gsicc.c | 3 | ||||
-rw-r--r-- | base/gspcolor.c | 4 | ||||
-rw-r--r-- | base/gxcspace.h | 2 |
8 files changed, 49 insertions, 33 deletions
diff --git a/base/gscdevn.c b/base/gscdevn.c index 94ffc5627..f0c2cae6c 100644 --- a/base/gscdevn.c +++ b/base/gscdevn.c @@ -770,7 +770,7 @@ gx_set_overprint_DeviceN(const gs_color_space * pcs, gs_gstate * pgs) /* Finalize contents of a DeviceN color space. */ static void -gx_final_DeviceN(const gs_color_space * pcs) +gx_final_DeviceN(gs_color_space * pcs) { gs_device_n_colorant * pnextatt, * patt = pcs->params.device_n.colorants; uint num_proc_names = pcs->params.device_n.num_process_names; @@ -797,6 +797,8 @@ gx_final_DeviceN(const gs_color_space * pcs) rc_decrement(patt, "gx_adjust_DeviceN"); patt = pnextatt; } + /* Ensure idempotency */ + memset(&pcs->params.device_n, 0, sizeof(pcs->params.device_n)); } /* ---------------- Serialization. -------------------------------- */ diff --git a/base/gscolor2.c b/base/gscolor2.c index 85238bf49..e730ae02c 100644 --- a/base/gscolor2.c +++ b/base/gscolor2.c @@ -294,16 +294,18 @@ gx_set_overprint_Indexed(const gs_color_space * pcs, gs_gstate * pgs) /* Color space finalization ditto. */ static void -gx_final_Indexed(const gs_color_space * pcs) +gx_final_Indexed(gs_color_space * pcs) { if (pcs->params.indexed.use_proc) { rc_adjust_const(pcs->params.indexed.lookup.map, -1, "gx_adjust_Indexed"); + pcs->params.indexed.lookup.map = NULL; } else { byte *data = (byte *)pcs->params.indexed.lookup.table.data; /* Break 'const'. */ gs_free_string(pcs->rc.memory, data, pcs->params.indexed.lookup.table.size, "gx_final_Indexed"); + pcs->params.indexed.lookup.table.data = NULL; } } diff --git a/base/gscscie.c b/base/gscscie.c index 3bc94aed6..d39f0244d 100644 --- a/base/gscscie.c +++ b/base/gscscie.c @@ -148,59 +148,63 @@ gx_install_CIE(gs_color_space * pcs, gs_gstate * pgs) /* Free params for a CIE color space */ static void -gx_final_CIEDEFG(const gs_color_space * pcs) +gx_final_CIEDEFG(gs_color_space * pcs) { - gs_color_space *pcs_noconst = (gs_color_space *)pcs; - if (pcs->icc_equivalent != NULL) { - rc_decrement(pcs_noconst->icc_equivalent, "gx_final_CIEDEFG"); + rc_decrement(pcs->icc_equivalent, "gx_final_CIEDEFG"); + pcs->icc_equivalent = NULL; } if (pcs->cmm_icc_profile_data != NULL) { - gsicc_adjust_profile_rc(pcs_noconst->cmm_icc_profile_data, -1, "gx_final_CIEDEFG"); + gsicc_adjust_profile_rc(pcs->cmm_icc_profile_data, -1, "gx_final_CIEDEFG"); + pcs->cmm_icc_profile_data = NULL; } - rc_decrement(pcs_noconst->params.defg, "gx_final_CIEDEFG"); + rc_decrement(pcs->params.defg, "gx_final_CIEDEFG"); + pcs->params.defg = NULL; } static void -gx_final_CIEDEF(const gs_color_space * pcs) +gx_final_CIEDEF(gs_color_space * pcs) { - gs_color_space *pcs_noconst = (gs_color_space *)pcs; - if (pcs->icc_equivalent != NULL) { - rc_decrement(pcs_noconst->icc_equivalent,"gx_final_CIEDEF"); + rc_decrement(pcs->icc_equivalent,"gx_final_CIEDEF"); + pcs->icc_equivalent = NULL; } if (pcs->cmm_icc_profile_data != NULL) { - gsicc_adjust_profile_rc(pcs_noconst->cmm_icc_profile_data, -1, "gx_final_CIEDEF"); + gsicc_adjust_profile_rc(pcs->cmm_icc_profile_data, -1, "gx_final_CIEDEF"); + pcs->cmm_icc_profile_data = NULL; } - rc_decrement(pcs_noconst->params.def, "gx_final_CIEDEF"); + rc_decrement(pcs->params.def, "gx_final_CIEDEF"); + pcs->params.def = NULL; } static void -gx_final_CIEABC(const gs_color_space * pcs) +gx_final_CIEABC(gs_color_space * pcs) { - gs_color_space *pcs_noconst = (gs_color_space *)pcs; - if (pcs->icc_equivalent != NULL) { - rc_decrement(pcs_noconst->icc_equivalent,"gx_final_CIEABC"); + rc_decrement(pcs->icc_equivalent,"gx_final_CIEABC"); + pcs->icc_equivalent = NULL; } if (pcs->cmm_icc_profile_data != NULL) { - gsicc_adjust_profile_rc(pcs_noconst->cmm_icc_profile_data, -1, "gx_final_CIEABC"); + gsicc_adjust_profile_rc(pcs->cmm_icc_profile_data, -1, "gx_final_CIEABC"); + pcs->cmm_icc_profile_data = NULL; } - rc_decrement(pcs_noconst->params.abc, "gx_final_CIEABC"); + rc_decrement(pcs->params.abc, "gx_final_CIEABC"); + pcs->params.abc = NULL; } static void -gx_final_CIEA(const gs_color_space * pcs) +gx_final_CIEA(gs_color_space * pcs) { - gs_color_space *pcs_noconst = (gs_color_space *)pcs; - if (pcs->icc_equivalent != NULL) { - rc_decrement(pcs_noconst->icc_equivalent,"gx_final_CIEA"); + rc_decrement(pcs->icc_equivalent,"gx_final_CIEA"); + pcs->icc_equivalent = NULL; } if (pcs->cmm_icc_profile_data != NULL) { - gsicc_adjust_profile_rc(pcs_noconst->cmm_icc_profile_data, -1, "gx_final_CIEA"); + gsicc_adjust_profile_rc(pcs->cmm_icc_profile_data, -1, "gx_final_CIEA"); + pcs->cmm_icc_profile_data = NULL; } - rc_decrement(pcs_noconst->params.a, "gx_adjust_cspace_CIEA"); + rc_decrement(pcs->params.a, "gx_adjust_cspace_CIEA"); + pcs->params.a = NULL; } /* ---------------- Procedures ---------------- */ diff --git a/base/gscsepr.c b/base/gscsepr.c index 341189885..0e6544fa1 100644 --- a/base/gscsepr.c +++ b/base/gscsepr.c @@ -210,11 +210,13 @@ gx_set_overprint_Separation(const gs_color_space * pcs, gs_gstate * pgs) /* Finalize contents of a Separation color space. */ static void -gx_final_Separation(const gs_color_space * pcs) +gx_final_Separation(gs_color_space * pcs) { rc_adjust_const(pcs->params.separation.map, -1, "gx_adjust_Separation"); + pcs->params.separation.map = NULL; gs_free_object(pcs->params.separation.mem, pcs->params.separation.sep_name, "gx_final_Separation"); + pcs->params.separation.sep_name = NULL; } /* ------ Constructors/accessors ------ */ diff --git a/base/gscspace.c b/base/gscspace.c index 1a8fef6ad..50a64dcbb 100644 --- a/base/gscspace.c +++ b/base/gscspace.c @@ -92,6 +92,8 @@ public_st_base_color_space(); /* ------ Create/copy/destroy ------ */ +/* Ghostscript object finalizers can be called many times and hence + * must be idempotent. */ static void gs_cspace_final(const gs_memory_t *cmem, void *vptr) { @@ -100,17 +102,20 @@ gs_cspace_final(const gs_memory_t *cmem, void *vptr) if (pcs->interpreter_free_cspace_proc != NULL) { (*pcs->interpreter_free_cspace_proc) ((gs_memory_t *)cmem, pcs); + pcs->interpreter_free_cspace_proc = NULL; } if (pcs->type->final) pcs->type->final(pcs); if_debug2m('c', cmem, "[c]cspace final "PRI_INTPTR" %d\n", (intptr_t)pcs, (int)pcs->id); rc_decrement_only_cs(pcs->base_space, "gs_cspace_final"); - if (pcs->params.device_n.devn_process_space != NULL) + pcs->base_space = NULL; + if (pcs->params.device_n.devn_process_space != NULL) { rc_decrement_only_cs(pcs->params.device_n.devn_process_space, "gs_cspace_final"); + pcs->params.device_n.devn_process_space = NULL; + } /* No need to decrement the ICC profile data. It is handled by the finalize of the ICC space which is called above using pcs->type->final(pcs); */ - } static gs_color_space * diff --git a/base/gsicc.c b/base/gsicc.c index f77d7028f..de91770d2 100644 --- a/base/gsicc.c +++ b/base/gsicc.c @@ -615,10 +615,11 @@ gx_concretize_ICC( * unintuitive but otherwise legitimate state of affairs". */ static void -gx_final_ICC(const gs_color_space * pcs) +gx_final_ICC(gs_color_space * pcs) { if (pcs->cmm_icc_profile_data != NULL) { gsicc_adjust_profile_rc(pcs->cmm_icc_profile_data, -1, "gx_final_ICC"); + pcs->cmm_icc_profile_data = NULL; } } diff --git a/base/gspcolor.c b/base/gspcolor.c index 4fb536805..417fb1399 100644 --- a/base/gspcolor.c +++ b/base/gspcolor.c @@ -293,7 +293,7 @@ gx_set_overprint_Pattern(const gs_color_space * pcs, gs_gstate * pgs) /* Adjust the reference counts for Pattern color spaces or colors. */ static void -gx_final_Pattern(const gs_color_space * pcs) +gx_final_Pattern(gs_color_space * pcs) { /* {csrc} really do nothing? */ } @@ -305,7 +305,7 @@ gx_adjust_color_Pattern(const gs_client_color * pcc, gs_pattern_instance_t *pinst = pcc->pattern; rc_adjust_only(pinst, delta, "gx_adjust_color_Pattern"); - if (pcs && pcs->params.pattern.has_base_space) + if (pcs && pcs->base_space && pcs->params.pattern.has_base_space) (pcs->base_space->type->adjust_color_count) (pcc, pcs->base_space, delta); } diff --git a/base/gxcspace.h b/base/gxcspace.h index 9fd037241..56f2d183f 100644 --- a/base/gxcspace.h +++ b/base/gxcspace.h @@ -152,7 +152,7 @@ struct gs_color_space_type_s { /* Free contents of composite colorspace objects. */ #define cs_proc_final(proc)\ - void proc(const gs_color_space *) + void proc(gs_color_space *) cs_proc_final((*final)); /* Adjust reference counts of indirect color components. */ |