diff options
Diffstat (limited to 'base/gslibctx.c')
-rw-r--r-- | base/gslibctx.c | 105 |
1 files changed, 44 insertions, 61 deletions
diff --git a/base/gslibctx.c b/base/gslibctx.c index 64e214d6..fbfd9143 100644 --- a/base/gslibctx.c +++ b/base/gslibctx.c @@ -79,12 +79,15 @@ gs_lib_ctx_set_icc_directory(const gs_memory_t *mem_gc, const char* pname, } gs_free_object(p_ctx_mem, p_ctx->profiledir, "gs_lib_ctx_set_icc_directory"); + p_ctx->profiledir = NULL; + p_ctx->profiledir_len = 0; } /* User param string. Must allocate in non-gc memory */ result = (char*) gs_alloc_bytes(p_ctx_mem, dir_namelen+1, "gs_lib_ctx_set_icc_directory"); - if (result == NULL) + if (result == NULL) { return -1; + } strcpy(result, pname); p_ctx->profiledir = result; p_ctx->profiledir_len = dir_namelen; @@ -262,14 +265,10 @@ int gs_lib_ctx_init(gs_lib_ctx_t *ctx, gs_memory_t *mem) memset(pio, 0, sizeof(*pio)); if (ctx != NULL) { -#ifdef MEMENTO_SQUEEZE_BUILD - goto Failure; -#else pio->core = ctx->core; gx_monitor_enter((gx_monitor_t *)(pio->core->monitor)); pio->core->refs++; gx_monitor_leave((gx_monitor_t *)(pio->core->monitor)); -#endif /* MEMENTO_SQUEEZE_BUILD */ } else { pio->core = (gs_lib_ctx_core_t *)gs_alloc_bytes_immovable(mem, sizeof(gs_lib_ctx_core_t), @@ -305,7 +304,6 @@ int gs_lib_ctx_init(gs_lib_ctx_t *ctx, gs_memory_t *mem) pio->core->fs->memory = mem; pio->core->fs->next = NULL; -#ifndef MEMENTO_SQUEEZE_BUILD pio->core->monitor = gx_monitor_alloc(mem); if (pio->core->monitor == NULL) { #ifdef WITH_CAL @@ -316,7 +314,6 @@ int gs_lib_ctx_init(gs_lib_ctx_t *ctx, gs_memory_t *mem) gs_free_object(mem, pio, "gs_lib_ctx_init"); return -1; } -#endif /* MEMENTO_SQUEEZE_BUILD */ pio->core->refs = 1; pio->core->memory = mem; @@ -414,17 +411,11 @@ void gs_lib_ctx_fin(gs_memory_t *mem) mem_err_print = NULL; #endif -#ifndef MEMENTO_SQUEEZE_BUILD gx_monitor_enter((gx_monitor_t *)(ctx->core->monitor)); -#endif refs = --ctx->core->refs; -#ifndef MEMENTO_SQUEEZE_BUILD gx_monitor_leave((gx_monitor_t *)(ctx->core->monitor)); -#endif if (refs == 0) { -#ifndef MEMENTO_SQUEEZE_BUILD gx_monitor_free((gx_monitor_t *)(ctx->core->monitor)); -#endif #ifdef WITH_CAL cal_fin(ctx->core->cal_ctx, ctx->core->memory); #endif @@ -577,7 +568,7 @@ gs_check_file_permission (gs_memory_t *mem, const char *fname, const int len, co return code; } -static int +static void rewrite_percent_specifiers(char *s) { char *match_start; @@ -589,7 +580,7 @@ rewrite_percent_specifiers(char *s) while (*s && *s != '%') s++; if (*s == 0) - return 0; + return; match_start = s; s++; /* Skip over flags (just one instance of any given flag, in any order) */ @@ -629,10 +620,9 @@ rewrite_percent_specifiers(char *s) *s == 'X') { /* Success! */ memset(match_start, '*', s - match_start + 1); - return 1; + return; } } - return 0; } /* For the OutputFile permission we have to deal with formattable strings @@ -648,6 +638,7 @@ gs_add_outputfile_control_path(gs_memory_t *mem, const char *fname) char *fp, f[gp_file_name_sizeof]; const int pipe = 124; /* ASCII code for '|' */ const int len = strlen(fname); + int i; /* Be sure the string copy will fit */ if (len >= gp_file_name_sizeof) @@ -655,29 +646,25 @@ gs_add_outputfile_control_path(gs_memory_t *mem, const char *fname) strcpy(f, fname); fp = f; /* Try to rewrite any %d (or similar) in the string */ - if (!rewrite_percent_specifiers(f)) { - /* No %d found, so check for pipes */ - int i; - fp = f; - for (i = 0; i < len; i++) { - if (f[i] == pipe) { - int code; - - fp = &f[i + 1]; - /* Because we potentially have to check file permissions at two levels - for the output file (gx_device_open_output_file and the low level - fopen API, if we're using a pipe, we have to add both the full string, - (including the '|', and just the command to which we pipe - since at - the pipe_fopen(), the leading '|' has been stripped. - */ - code = gs_add_control_path(mem, gs_permit_file_writing, f); - if (code < 0) - return code; - break; - } - if (!IS_WHITESPACE(f[i])) - break; + rewrite_percent_specifiers(f); + for (i = 0; i < len; i++) { + if (f[i] == pipe) { + int code; + + fp = &f[i + 1]; + /* Because we potentially have to check file permissions at two levels + for the output file (gx_device_open_output_file and the low level + fopen API, if we're using a pipe, we have to add both the full string, + (including the '|', and just the command to which we pipe - since at + the pipe_fopen(), the leading '|' has been stripped. + */ + code = gs_add_control_path(mem, gs_permit_file_writing, f); + if (code < 0) + return code; + break; } + if (!IS_WHITESPACE(f[i])) + break; } return gs_add_control_path(mem, gs_permit_file_writing, fp); } @@ -688,6 +675,7 @@ gs_remove_outputfile_control_path(gs_memory_t *mem, const char *fname) char *fp, f[gp_file_name_sizeof]; const int pipe = 124; /* ASCII code for '|' */ const int len = strlen(fname); + int i; /* Be sure the string copy will fit */ if (len >= gp_file_name_sizeof) @@ -695,29 +683,24 @@ gs_remove_outputfile_control_path(gs_memory_t *mem, const char *fname) strcpy(f, fname); fp = f; /* Try to rewrite any %d (or similar) in the string */ - if (!rewrite_percent_specifiers(f)) { - /* No %d found, so check for pipes */ - int i; - fp = f; - for (i = 0; i < len; i++) { - if (f[i] == pipe) { - int code; - - fp = &f[i + 1]; - /* Because we potentially have to check file permissions at two levels - for the output file (gx_device_open_output_file and the low level - fopen API, if we're using a pipe, we have to add both the full string, - (including the '|', and just the command to which we pipe - since at - the pipe_fopen(), the leading '|' has been stripped. - */ - code = gs_remove_control_path(mem, gs_permit_file_writing, f); - if (code < 0) - return code; - break; - } - if (!IS_WHITESPACE(f[i])) - break; + for (i = 0; i < len; i++) { + if (f[i] == pipe) { + int code; + + fp = &f[i + 1]; + /* Because we potentially have to check file permissions at two levels + for the output file (gx_device_open_output_file and the low level + fopen API, if we're using a pipe, we have to add both the full string, + (including the '|', and just the command to which we pipe - since at + the pipe_fopen(), the leading '|' has been stripped. + */ + code = gs_remove_control_path(mem, gs_permit_file_writing, f); + if (code < 0) + return code; + break; } + if (!IS_WHITESPACE(f[i])) + break; } return gs_remove_control_path(mem, gs_permit_file_writing, fp); } |