shithub: jbig2

Download patch

ref: 301726dd5c9c60c1e54eb0965c1d45b36350ce2e
parent: c17e4d59c885cf7197bc62c8f9c82be277b81aa3
author: Sebastian Rasmussen <sebras@gmail.com>
date: Sun May 14 13:50:32 EDT 2017

Plug leak of parameter info in command-line tool.

--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -390,6 +390,7 @@
     uint8_t buf[4096];
     jbig2dec_params_t params;
     int filearg;
+    int result = 0;
 
     /* set defaults */
     params.mode = render;
@@ -421,7 +422,7 @@
             f = fopen(fn, "rb");
             if (f == NULL) {
                 fprintf(stderr, "error opening %s\n", fn);
-                return 1;
+                goto cleanup;
             }
         } else if ((argc - filearg) == 2)
             /* two arguments open as separate global and page streams */
@@ -432,7 +433,7 @@
             f = fopen(fn, "rb");
             if (f == NULL) {
                 fprintf(stderr, "error opening %s\n", fn);
-                return 1;
+                goto cleanup;
             }
 
             f_page = fopen(fn_page, "rb");
@@ -439,11 +440,13 @@
             if (f_page == NULL) {
                 fclose(f);
                 fprintf(stderr, "error opening %s\n", fn_page);
-                return 1;
+                goto cleanup;
             }
-        } else
+        } else {
             /* any other number of arguments */
-            return print_usage();
+            result = print_usage();
+            goto cleanup;
+        }
 
         ctx = jbig2_ctx_new(NULL, (Jbig2Options)(f_page != NULL ? JBIG2_OPTIONS_EMBEDDED : 0), NULL, error_callback, &params);
 
@@ -514,11 +517,14 @@
 
     }                           /* end params.mode switch */
 
+    /* fin */
+    result = 1;
+
+cleanup:
     if (params.output_file)
         free(params.output_file);
     if (params.hash)
         hash_free(&params);
 
-    /* fin */
-    return 0;
+    return result;
 }