Merge pull request #1211 from sebras/master
[openjpeg.git] / src / bin / jpwl / opj_jpwl_compress.c
index 7f215fc50e9e871e8f1d078331e372bb7ccf4e2f..ccf0361500250046a2199b38f526e8f772ba21cc 100644 (file)
@@ -952,8 +952,9 @@ static int parse_cmdline_encoder(int argc, char **argv,
         case 'b': {         /* code-block dimension */
             int cblockw_init = 0, cblockh_init = 0;
             sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
-            if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
-                    || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
+            if (cblockw_init > 1024 || cblockw_init < 4 ||
+                    cblockh_init > 1024 || cblockh_init < 4 ||
+                    cblockw_init * cblockh_init > 4096) {
                 fprintf(stderr,
                         "!! Size of code_block error (option -b) !!\n\nRestriction :\n"
                         "    * width*height<=4096\n    * 4<=width,height<= 1024\n\n");
@@ -1629,7 +1630,7 @@ int main(int argc, char **argv)
 
     /*
     configure the event callbacks (not required)
-    setting of each callback is optionnal
+    setting of each callback is optional
     */
     memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
     event_mgr.error_handler = error_callback;
@@ -1680,8 +1681,15 @@ int main(int argc, char **argv)
         if (dirptr) {
             dirptr->filename_buf = (char*)malloc(num_images * OPJ_PATH_LEN * sizeof(
                     char)); /* Stores at max 10 image file names*/
-            dirptr->filename = (char**) malloc(num_images * sizeof(char*));
             if (!dirptr->filename_buf) {
+                free(parameters.cp_comment);
+                free(dirptr);
+                return 0;
+            }
+            dirptr->filename = (char**) malloc(num_images * sizeof(char*));
+            if (!dirptr->filename) {
+                free(parameters.cp_comment);
+                free(dirptr);
                 return 0;
             }
             for (i = 0; i < num_images; i++) {
@@ -1689,9 +1697,13 @@ int main(int argc, char **argv)
             }
         }
         if (load_images(dirptr, img_fol.imgdirpath) == 1) {
+            free(parameters.cp_comment);
+            free(dirptr);
             return 0;
         }
         if (num_images == 0) {
+            free(parameters.cp_comment);
+            free(dirptr);
             fprintf(stdout, "Folder is empty\n");
             return 0;
         }
@@ -1849,6 +1861,7 @@ int main(int argc, char **argv)
             if (res < (size_t)codestream_length) {  /* FIXME */
                 fprintf(stderr, "failed to write %d (%s)\n", codestream_length,
                         parameters.outfile);
+                fclose(f);
                 return 1;
             }
             fclose(f);
@@ -1913,6 +1926,7 @@ int main(int argc, char **argv)
             if (res < (size_t)codestream_length) {  /* FIXME */
                 fprintf(stderr, "failed to write %d (%s)\n", codestream_length,
                         parameters.outfile);
+                fclose(f);
                 return 1;
             }
             fclose(f);