shithub: jbig2

Download patch

ref: b009e994db066f204f85cb7935ebd5e7a0e1cb6c
parent: d663f59b034d429d850cca7e84d0017eb6e5cda3
author: Simon Bünzli <[email protected]>
date: Sun Sep 1 08:23:04 EDT 2013

bug 694281: fix memory leaks and compilation warnings

* jbig2_build_huffman_table leaks LENCOUNT and result under OOM conditions
* jbig2_decode_symbol_dict leaks an image in an error case
* jbig2_symbol_dictionary skips cleanup in an error case
* jbig2_text_region leaks GR_stats in various error and non-error cases
* MSVC reports two "unreachable code" warnings and a "signed/unsigned
  mismatch" one

--- a/jbig2.c
+++ b/jbig2.c
@@ -390,7 +390,6 @@
 		      "Garbage beyond end of file");
 	}
     }
-  return 0;
 }
 
 void
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -414,6 +414,7 @@
   {
     jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
         "couldn't allocate result storage in jbig2_build_huffman_table");
+    jbig2_free(ctx->allocator, LENCOUNT);
     return NULL;
   }
   result->log_table_size = log_table_size;
@@ -422,6 +423,8 @@
   {
     jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
         "couldn't allocate entries storage in jbig2_build_huffman_table");
+    jbig2_free(ctx->allocator, result);
+    jbig2_free(ctx->allocator, LENCOUNT);
     return NULL;
   }
   /* fill now to catch missing JBIG2Globals later */
@@ -565,7 +568,7 @@
         size_t boffset = 0;
         /* B.2 4) */
         int32_t CURRANGELOW = HTLOW;
-        int NTEMP = 0;
+        size_t NTEMP = 0;
 
 #ifdef JBIG2_DEBUG
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, 
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -244,8 +244,6 @@
                     "unhandled extension segment");
             }
     }
-
-    return 0;
 }
 
 /* general segment parsing dispatch */
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -442,7 +442,10 @@
 
 		  code = jbig2_decode_generic_region(ctx, segment, &region_params,
               as, image, GB_stats);
-          if (code < 0) goto cleanup4;
+          if (code < 0) {
+              jbig2_image_release(ctx, image);
+              goto cleanup4;
+          }
 
           SDNEWSYMS->glyphs[NSYMSDECODED] = image;
 	      } else {
@@ -950,7 +953,7 @@
         break;
       case 2:
       default:
-	return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+	jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 	    "symbol dictionary specified invalid huffman table");
 	break;
     }
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -857,7 +857,7 @@
     if (image == NULL) {
         code =jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
             "couldn't allocate text region image");
-        goto cleanup1;
+        goto cleanup2;
     }
 
     ws = jbig2_word_stream_buf_new(ctx, segment_data + offset, segment->data_length - offset);
@@ -957,9 +957,7 @@
     jbig2_word_stream_buf_free(ctx, ws);
 
 cleanup2:
-    if (!params.SBHUFF && params.SBREFINE) {
-        jbig2_free(ctx->allocator, GR_stats);
-    }
+    jbig2_free(ctx->allocator, GR_stats);
     jbig2_image_release(ctx, image);
 
 cleanup1: