diff options
Diffstat (limited to 'xps/xps_zip.c')
-rw-r--r-- | xps/xps_zip.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/xps/xps_zip.c b/xps/xps_zip.c index e1019ae0..ccf82027 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -391,15 +391,25 @@ xps_read_part(xps_context *ctx, char *partname) } int -xps_open_file(xps_context *ctx, char *filename) +xps_open_file(xps_context **ctxp, char *filename) { + xps_context *ctx; char buf[2048]; int code; char *p; + ctx = fz_malloc(sizeof(xps_context)); + memset(ctx, 0, sizeof(xps_context)); + ctx->font_table = xps_hash_new(); + ctx->colorspace_table = xps_hash_new(); + ctx->start_part = NULL; + ctx->file = fopen(filename, "rb"); if (!ctx->file) + { + xps_free_context(ctx); return fz_throw("cannot open file: '%s'", filename); + } if (strstr(filename, "/_rels/.rels") || strstr(filename, "\\_rels\\.rels")) { @@ -414,33 +424,23 @@ xps_open_file(xps_context *ctx, char *filename) { code = xps_find_and_read_zip_dir(ctx); if (code < 0) + { + xps_free_context(ctx); return fz_rethrow(code, "cannot read zip central directory"); + } } code = xps_read_page_list(ctx); if (code) + { + xps_free_context(ctx); return fz_rethrow(code, "cannot read page list"); + } + *ctxp = ctx; return fz_okay; } -xps_context * -xps_new_context(void) -{ - xps_context *ctx; - - ctx = fz_malloc(sizeof(xps_context)); - - memset(ctx, 0, sizeof(xps_context)); - - ctx->font_table = xps_hash_new(); - ctx->colorspace_table = xps_hash_new(); - - ctx->start_part = NULL; - - return ctx; -} - static void xps_free_key_func(void *ptr) { fz_free(ptr); @@ -456,7 +456,7 @@ static void xps_free_colorspace_func(void *ptr) fz_drop_colorspace(ptr); } -int +void xps_free_context(xps_context *ctx) { int i; @@ -464,19 +464,15 @@ xps_free_context(xps_context *ctx) if (ctx->file) fclose(ctx->file); - if (ctx->start_part) - fz_free(ctx->start_part); - for (i = 0; i < ctx->zip_count; i++) fz_free(ctx->zip_table[i].name); fz_free(ctx->zip_table); xps_hash_free(ctx->font_table, xps_free_key_func, xps_free_font_func); xps_hash_free(ctx->colorspace_table, xps_free_key_func, xps_free_colorspace_func); - xps_free_page_list(ctx); + fz_free(ctx->start_part); + fz_free(ctx->directory); fz_free(ctx); - - return 0; } |