[trunk] Properly handle failure to compress (remove file)
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 28 Apr 2014 07:54:33 +0000 (07:54 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 28 Apr 2014 07:54:33 +0000 (07:54 +0000)
Fixes issue 323

src/bin/jp2/opj_compress.c
src/bin/jp2/opj_decompress.c

index 41959e201f24f9d0e471f6c79ddb3a67aed50245..f0ff3e4de9a239e2dd9caaa39bcc59c902b2147c 100644 (file)
@@ -1789,7 +1789,7 @@ int main(int argc, char **argv) {
         if (!bSuccess)  {
             fprintf(stderr, "failed to encode image: opj_start_compress\n");
         }
-        if( bUseTiles ) {
+        if( bSuccess && bUseTiles ) {
             OPJ_BYTE *l_data;
             OPJ_UINT32 l_data_size = 512*512*3;
             l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE));
@@ -1822,6 +1822,7 @@ int main(int argc, char **argv) {
             opj_destroy_codec(l_codec);
             opj_image_destroy(image);
             fprintf(stderr, "failed to encode image\n");
+                       remove(parameters.outfile);
             return 1;
         }
 
index 1362a1bc8463daa8b3fb313e5fa1633ba36c16dd..3bcf947fa9500e4914203f2d08ef1283c7e8ce28 100644 (file)
@@ -972,6 +972,7 @@ int main(int argc, char **argv)
                /* destroy the codestream index */
                opj_destroy_cstr_index(&cstr_index);
 
+               if(failed) remove(parameters.outfile);
        }
        return failed ? EXIT_FAILURE : EXIT_SUCCESS;
 }