[trunk] Properly handle failure to compress (remove file)

Fixes issue 323
This commit is contained in:
Mathieu Malaterre 2014-04-28 07:54:33 +00:00
parent de04302c15
commit 4bac8488df
2 changed files with 3 additions and 1 deletions

View File

@ -1789,7 +1789,7 @@ int main(int argc, char **argv) {
if (!bSuccess) { if (!bSuccess) {
fprintf(stderr, "failed to encode image: opj_start_compress\n"); fprintf(stderr, "failed to encode image: opj_start_compress\n");
} }
if( bUseTiles ) { if( bSuccess && bUseTiles ) {
OPJ_BYTE *l_data; OPJ_BYTE *l_data;
OPJ_UINT32 l_data_size = 512*512*3; OPJ_UINT32 l_data_size = 512*512*3;
l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE)); 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_destroy_codec(l_codec);
opj_image_destroy(image); opj_image_destroy(image);
fprintf(stderr, "failed to encode image\n"); fprintf(stderr, "failed to encode image\n");
remove(parameters.outfile);
return 1; return 1;
} }

View File

@ -972,6 +972,7 @@ int main(int argc, char **argv)
/* destroy the codestream index */ /* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index); opj_destroy_cstr_index(&cstr_index);
if(failed) remove(parameters.outfile);
} }
return failed ? EXIT_FAILURE : EXIT_SUCCESS; return failed ? EXIT_FAILURE : EXIT_SUCCESS;
} }