ref: e3a50c85fa43ebff2b3164e05cf3988c326cfb27
parent: de271483ae5bf0ee87b73b44d9d433d4ca6a920a
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Jan 3 19:53:10 EST 2005
Properly free arithmetic coding and word stream states after region decode. Also use the allocator defined in the library context instead of raw malloc for the arith state. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@381 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -1,7 +1,7 @@
/*
jbig2dec
- Copyright (c) 2001 artofcode LLC.
+ Copyright (c) 2001-2005 artofcode LLC.
This software is provided AS-IS with no warranty,
either express or implied.
@@ -174,10 +174,17 @@
}
#endif
+/** Allocate and initialize a new arithmetic coding state
+ * the returned pointer can simply be freed; this does
+ * not affect the associated Jbig2WordStream.
+ */
Jbig2ArithState *
jbig2_arith_new (Jbig2Ctx *ctx, Jbig2WordStream *ws)
{
- Jbig2ArithState *result = (Jbig2ArithState *)malloc (sizeof(Jbig2ArithState));
+ Jbig2ArithState *result;
+
+ result = (Jbig2ArithState *)jbig2_alloc(ctx->allocator,
+ sizeof(Jbig2ArithState));
result->ws = ws;
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -611,16 +611,17 @@
as = jbig2_arith_new(ctx, ws);
code = jbig2_decode_generic_region(ctx, segment, ¶ms,
as, image, GB_stats);
+ jbig2_free(ctx->allocator, as);
+ jbig2_word_stream_buf_free(ctx, ws);
+
+ jbig2_free(ctx->allocator, GB_stats);
}
- /* todo: free ws, as */
-
+
jbig2_image_compose(ctx, ctx->pages[ctx->current_page].image, image,
rsi.x, rsi.y, JBIG2_COMPOSE_OR);
jbig2_image_release(ctx, image);
- jbig2_free(ctx->allocator, GB_stats);
-
return code;
}
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -423,7 +423,8 @@
code = jbig2_decode_refinement_region(ctx, segment, ¶ms,
as, image, GR_stats);
- /* TODO: free ws, as */
+ jbig2_free(ctx->allocator, as);
+ jbig2_word_stream_buf_free(ctx, ws);
jbig2_free(ctx->allocator, GR_stats);
if ((segment->flags & 63) == 40) {