[trunk] WIP: solve some memory leak in test compare functions

This commit is contained in:
Mickael Savinaud 2011-10-19 13:06:49 +00:00
parent 436318a8c8
commit 5b93ae8628
3 changed files with 77 additions and 16 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
October 19, 2011
* [mickael] WIP: resolve some memory leak in compare functions
October 12, 2011 October 12, 2011
* [mickael] WIP: resolve heap corruption with p0_07.j2k (credit to Winfried) * [mickael] WIP: resolve heap corruption with p0_07.j2k (credit to Winfried)
* [mickael] WIP: correct some memory leaks in applications functions * [mickael] WIP: correct some memory leaks in applications functions

View File

@ -321,7 +321,10 @@ double* parseToleranceValues( char* inArg, const int nbcomp)
} }
if (it_comp != nbcomp) if (it_comp != nbcomp)
{
free(outArgs);
return NULL; return NULL;
}
else else
return outArgs; return outArgs;
} }
@ -408,7 +411,18 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ
image_read = pgxtoimage(filenameComponentPGX, &parameters); image_read = pgxtoimage(filenameComponentPGX, &parameters);
if (!image_read) if (!image_read)
{ {
int it_free_data;
fprintf(stderr, "Unable to load pgx file\n"); fprintf(stderr, "Unable to load pgx file\n");
free(param_image_read);
for (it_free_data = 0; it_free_data < it_file; it_free_data++) {
free(data[it_free_data]);
}
free(data);
free(filenameComponentPGX);
return NULL; return NULL;
} }
@ -498,10 +512,10 @@ int main(int argc, char **argv)
if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE ) if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE )
{ {
comparePGXimages_help_display(); comparePGXimages_help_display();
if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues); if (inParam.tabMSEvalues) free(inParam.tabMSEvalues);
if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues); if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
if (!inParam.base_filename) free(inParam.base_filename); if (inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename); if (inParam.test_filename) free(inParam.test_filename);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -560,10 +574,10 @@ int main(int argc, char **argv)
} }
else else
{ {
if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues); if (inParam.tabMSEvalues) free(inParam.tabMSEvalues);
if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues); if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
if (!inParam.base_filename) free(inParam.base_filename); if (inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename); if (inParam.test_filename) free(inParam.test_filename);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -582,10 +596,10 @@ int main(int argc, char **argv)
} }
else else
{ {
if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues); if (inParam.tabMSEvalues) free(inParam.tabMSEvalues);
if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues); if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
if (!inParam.base_filename) free(inParam.base_filename); if (inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename); if (inParam.test_filename) free(inParam.test_filename);
free(filenamePNGbase); free(filenamePNGbase);
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -127,18 +127,52 @@ int main(int argc, char **argv)
if (parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE) if (parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE)
{ {
compareRAWimages_help_display(); compareRAWimages_help_display();
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
return EXIT_FAILURE; return EXIT_FAILURE;
} }
file_test = fopen(inParam.test_filename, "rb"); file_test = fopen(inParam.test_filename, "rb");
if (!file_test) { if (!file_test) {
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename); fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename);
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
return EXIT_FAILURE; return EXIT_FAILURE;
} }
file_base = fopen(inParam.base_filename, "rb"); file_base = fopen(inParam.base_filename, "rb");
if (!file_base) { if (!file_base) {
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename); fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename);
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
fclose(file_test);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -179,6 +213,16 @@ int main(int argc, char **argv)
} }
} }
/* Free Memory */
if (inParam.base_filename){
free(inParam.base_filename);
inParam.base_filename = NULL;
}
if (inParam.test_filename){
free(inParam.test_filename);
inParam.test_filename = NULL;
}
fclose(file_test); fclose(file_test);
fclose(file_base); fclose(file_base);