diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2018-08-15 14:10:55 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2018-08-15 14:10:55 +0100 |
commit | 7ab21af0b0c70707aefb1083505136ff7862d337 (patch) | |
tree | 6435eb02b1577f3819c6ae88e36cba75471901e0 | |
parent | 1ff8b85ae28c7813aa484dd8f1779f4a4d0742af (diff) | |
download | ghostpdl-7ab21af0b0c70707aefb1083505136ff7862d337.tar.gz |
Bug 699638(3): Fix param list key handling in pl_main_process_options()
param lists can be configured to handle keys in two ways: persistent keys, or
transient keys. For persistent keys, the param list contains a reference to the
key string, and does no management of the string memory.
Configured for transient key strings, the param list makes a copy of the string
and the string memory is managed along with the parameter list itself.
The two approaches cannot be mixed in the same param list.
The pl_main_process_options() code configures the param list to use transient
key strings (which is the default). But it was then copying the key strings,
before passing them to the param list API, and taking no action to manage
the string memory - causing memory leaks.
Since the param list (as configured) takes a copy of the key string, there's no
call for the calling code to do so, and not doing the local string copy
prevents leaking memory.
-rw-r--r-- | pcl/pl/plmain.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/pcl/pl/plmain.c b/pcl/pl/plmain.c index 7619fa397..c4e9d293f 100644 --- a/pcl/pl/plmain.c +++ b/pcl/pl/plmain.c @@ -745,7 +745,6 @@ static int check_for_special_str(pl_main_instance_t * pmi, const char *arg, gs_p return 1; } -#define arg_heap_copy(str) arg_copy(str, pmi->memory) static int pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, pl_interp_implementation_t * pjli) @@ -858,7 +857,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (code == 1) code = param_write_bool((gs_param_list *) params, - arg_heap_copy(arg), &bval); + arg, &bval); continue; } @@ -871,7 +870,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, code = check_for_special_str(pmi, arg, &str); if (code == 1) code = param_write_name((gs_param_list *) params, - arg_heap_copy(buffer), &str); + buffer, &str); continue; } /* Search for a non-decimal 'radix' number */ @@ -911,7 +910,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (code == 1) code = param_write_int((gs_param_list *) params, - arg_heap_copy(buffer), &number); + buffer, &number); } else if ((!strchr(value, '.')) && /* search for an int (no decimal), if fail try a float */ (sscanf(value, "%d", &vi) == 1)) { @@ -943,7 +942,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (code == 1) code = param_write_int((gs_param_list *) params, - arg_heap_copy(buffer), &vi); + buffer, &vi); } else if (sscanf(value, "%f", &vf) == 1) { /* create a null terminated string. NB duplicated code. */ strncpy(buffer, arg, eqp - arg); @@ -952,7 +951,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (code == 1) code = param_write_float((gs_param_list *) params, - arg_heap_copy(buffer), &vf); + buffer, &vf); } else if (!strcmp(value, "true")) { /* bval = true; */ strncpy(buffer, arg, eqp - arg); @@ -961,7 +960,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (code == 1) code = param_write_bool((gs_param_list *) params, - arg_heap_copy(buffer), &bval); + buffer, &bval); } else if (!strcmp(value, "false")) { bval = false; strncpy(buffer, arg, eqp - arg); @@ -970,7 +969,7 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (code == 1) code = param_write_bool((gs_param_list *) params, - arg_heap_copy(buffer), &bval); + buffer, &bval); } else { dmprintf(pmi->memory, "Usage for -d is -d<option>=[<integer>|<float>|true|false]\n"); @@ -1216,21 +1215,21 @@ pl_main_process_options(pl_main_instance_t * pmi, arg_list * pal, if (!strncmp (arg, "DefaultGrayProfile", strlen("DefaultGrayProfile"))) { - pmi->pdefault_gray_icc = arg_heap_copy(value); + pmi->pdefault_gray_icc = arg_copy(value, pmi->memory); } else if (!strncmp (arg, "DefaultRGBProfile", strlen("DefaultRGBProfile"))) { - pmi->pdefault_rgb_icc = arg_heap_copy(value); + pmi->pdefault_rgb_icc = arg_copy(value, pmi->memory); } else if (!strncmp (arg, "DefaultCMYKProfile", strlen("DefaultCMYKProfile"))) { - pmi->pdefault_cmyk_icc = arg_heap_copy(value); + pmi->pdefault_cmyk_icc = arg_copy(value, pmi->memory); } else if (!strncmp (arg, "ICCProfileDir", strlen("ICCProfileDir"))) { - pmi->piccdir = arg_heap_copy(value); + pmi->piccdir = arg_copy(value, pmi->memory); } else { char buffer[128]; |