Closed memory leaks with demo/demo -iso_read and updated.

Inspired by Coverity CID 12561.
This commit is contained in:
Thomas Schmitt 2015-10-12 22:49:47 +02:00
parent 93e1fc52d0
commit 49dd9dc993
1 changed files with 38 additions and 23 deletions

View File

@ -493,37 +493,43 @@ iso_read_print_dir(IsoFileSource *dir, int level)
int gesture_iso_read(int argc, char **argv) int gesture_iso_read(int argc, char **argv)
{ {
int result; int result, initialized = 0, return_val = 1;
IsoImageFilesystem *fs; IsoImageFilesystem *fs = NULL;
IsoDataSource *src; IsoDataSource *src = NULL;
IsoFileSource *root; IsoFileSource *root = NULL;
IsoReadOpts *ropts; IsoReadOpts *ropts = NULL;
if (argc != 2) { if (argc != 2) {
printf ("You need to specify a valid path\n"); printf ("You need to specify a valid path\n");
return 1; goto ex;
} }
iso_init(); result = iso_init();
if (result < 0) {
demo_report_iso_err(result, "Cannot init libisofs");
goto ex;
}
initialized = 1;
iso_set_msgs_severities("NEVER", "ALL", ""); iso_set_msgs_severities("NEVER", "ALL", "");
result = iso_data_source_new_from_file(argv[1], &src); result = iso_data_source_new_from_file(argv[1], &src);
if (result < 0) { if (result < 0) {
printf ("Error creating data source\n"); demo_report_iso_err(result, "Error creating data source");
return 1; goto ex;
} }
result = iso_read_opts_new(&ropts, 0); result = iso_read_opts_new(&ropts, 0);
if (result < 0) { if (result < 0) {
fprintf(stderr, "Error creating read options\n"); demo_report_iso_err(result, "Error creating read options");
return 1; goto ex;
} }
result = iso_image_filesystem_new(src, ropts, 1, &fs); result = iso_image_filesystem_new(src, ropts, 1, &fs);
iso_read_opts_free(ropts);
if (result < 0) { if (result < 0) {
printf ("Error creating filesystem\n"); demo_report_iso_err(result, "Error creating filesystem");
return 1; goto ex;
} }
iso_read_opts_free(ropts);
ropts = NULL;
printf("\nVOLUME INFORMATION\n"); printf("\nVOLUME INFORMATION\n");
printf("==================\n\n"); printf("==================\n\n");
@ -542,18 +548,27 @@ int gesture_iso_read(int argc, char **argv)
result = fs->get_root(fs, &root); result = fs->get_root(fs, &root);
if (result < 0) { if (result < 0) {
printf ("Can't get root %d\n", result); demo_report_iso_err(result, "Cannot get root object");
return 1; goto ex;
} }
/* iso_read_print_file_src(root); */ /* iso_read_print_file_src(root); */
iso_read_print_dir(root, 0); iso_read_print_dir(root, 0);
iso_file_source_unref(root);
fs->close(fs); return_val = 0;
iso_filesystem_unref((IsoFilesystem*)fs); ex:;
iso_data_source_unref(src); if (root != NULL)
iso_finish(); iso_file_source_unref(root);
return 0; if (ropts != NULL)
iso_read_opts_free(ropts);
if (fs != NULL) {
fs->close(fs);
iso_filesystem_unref((IsoFilesystem*)fs);
}
if (src != NULL)
iso_data_source_unref(src);
if (initialized)
iso_finish();
return return_val;
} }