shithub: jbig2

Download patch

ref: a8ca8ed551e2897c422d0b6d46f1bd8ce30311b9
parent: 76c000e507efff47e6f625bddef0a93323a7cc9d
author: Shailesh Mistry <shailesh.mistry@hotmail.co.uk>
date: Fri Jun 22 12:56:39 EDT 2012

Bug 693050 : Fix minor typos and memory leak in 040d folder

--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -28,10 +28,6 @@
 #include "jbig2_priv.h"
 #include "jbig2_arith.h"
 
-#ifdef JBIG2_DEBUG
-#include <stdio.h>
-#endif
-
 struct _Jbig2ArithState {
   uint32_t C;
   int A;
@@ -194,7 +190,7 @@
   result->next_word_bytes = 4;
   result->offset = 4;
 
-  /* Figure G.1 */
+  /* Figure E.20 */
 #ifdef SOFTWARE_CONVENTION
   result->C = (~(result->next_word >> 8)) & 0xFF0000;
 #else
@@ -288,7 +284,7 @@
   const Jbig2ArithQe *pqe = &jbig2_arith_Qe[cx & 0x7f];
   bool D;
 
-  /* Figure G.2 */
+  /* Figure E.15 */
   as->A -= pqe->Qe;
   if (
 #ifdef SOFTWARE_CONVENTION
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -55,7 +55,8 @@
         image->data = jbig2_new(ctx, uint8_t, (int)check);
 	if (image->data == NULL) {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
-            "could not allocate image data buffer! [%d bytes]", stride*height);
+                "could not allocate image data buffer! [stride(%d)*height(%d) bytes]",
+                stride, height);
 		jbig2_free(ctx->allocator, image);
 		return NULL;
 	}
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -368,8 +368,8 @@
 	      DW = jbig2_huffman_get(hs, params->SDHUFFDW, &code);
 	  } else {
 	      code = jbig2_arith_int_decode(IADW, as, &DW);
-              if (code < 0) goto cleanup4;
 	  }
+          if (code < 0) goto cleanup4;
 
 	  /* 6.5.5 (4c.i) */
 	  if (code == 1) {
@@ -630,14 +630,14 @@
 	    SDNEWSYMWIDTHS[NSYMSDECODED] = SYMWIDTH;
 	  }
 
+          /* 6.5.5 (4c.iv) */
+          NSYMSDECODED = NSYMSDECODED + 1;
+
 	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
             "decoded symbol %u of %u (%ux%u)",
 		NSYMSDECODED, params->SDNUMNEWSYMS,
 		SYMWIDTH, HCHEIGHT);
 
-	  /* 6.5.5 (4c.iv) */
-	  NSYMSDECODED = NSYMSDECODED + 1;
-
       } /* end height class decode loop */
 
       /* 6.5.5 (4d) */
@@ -650,6 +650,7 @@
 	if (code || (BMSIZE < 0)) {
 	  jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 	    "error decoding size of collective bitmap!");
+          jbig2_image_release(ctx, image);
 	  goto cleanup4;
 	}
 
@@ -710,6 +711,7 @@
       {
           jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
               "failed to copy the collective bitmap into symbol dictionary");
+	  jbig2_image_release(ctx, image);
           goto cleanup4;
       }
 	  jbig2_image_compose(ctx, glyph, image, -x, 0, JBIG2_COMPOSE_REPLACE);
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -321,14 +321,6 @@
 		int code4 = 0;
 		int code5 = 0;
 
-		/* as must exist for refinement */
-		if (as == NULL)
-		{
-			code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
-				"as is NULL before refinement region");
-			goto cleanup2;
-		}
-
 		/* 6.4.11 (1, 2, 3, 4) */
 		if (!params->SBHUFF) {
 		  code1 = jbig2_arith_int_decode(params->IARDW, as, &RDW);
@@ -849,10 +841,19 @@
     ws = jbig2_word_stream_buf_new(ctx, segment_data + offset, segment->data_length - offset);
     if (ws == NULL)
     {
+         code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+            "couldn't allocate ws in text region image");
+        goto cleanup2;
+    }
+
+    as = jbig2_arith_new(ctx, ws);
+    if (as == NULL)
+    {
         code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
-            "couldn't allocate text region image");
+            "couldn't allocate as in text region image");
         goto cleanup2;
     }
+
     if (!params.SBHUFF) {
 	int SBSYMCODELEN, index;
         int SBNUMSYMS = 0;
@@ -860,12 +861,11 @@
 	    SBNUMSYMS += dicts[index]->n_symbols;
 	}
 
-	as = jbig2_arith_new(ctx, ws);
     params.IADT = jbig2_arith_int_ctx_new(ctx);
     params.IAFS = jbig2_arith_int_ctx_new(ctx);
     params.IADS = jbig2_arith_int_ctx_new(ctx);
     params.IAIT = jbig2_arith_int_ctx_new(ctx);
-    if ((as == NULL) || (params.IADT == NULL) || (params.IAFS == NULL) ||
+    if ((params.IADT == NULL) || (params.IAFS == NULL) ||
         (params.IADS == NULL) || (params.IAIT == NULL))
     {
         code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
@@ -894,8 +894,8 @@
     code = jbig2_decode_text_region(ctx, segment, &params,
         (const Jbig2SymbolDict * const *)dicts, n_dicts, image,
         segment_data + offset, segment->data_length - offset,
-		GR_stats, as, as ? NULL : ws);
-    if (code < 0)
+        GR_stats, as, ws);
+     if (code < 0)
     {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
             "failed to decode text region image data");
@@ -930,8 +930,8 @@
         jbig2_arith_int_ctx_free(ctx, params.IAFS);
         jbig2_arith_int_ctx_free(ctx, params.IADS);
         jbig2_arith_int_ctx_free(ctx, params.IAIT);
-        jbig2_free(ctx->allocator, as);
     }
+    jbig2_free(ctx->allocator, as);
     jbig2_word_stream_buf_free(ctx, ws);
 
 cleanup2: