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 result;
IsoImageFilesystem *fs;
IsoDataSource *src;
IsoFileSource *root;
IsoReadOpts *ropts;
int result, initialized = 0, return_val = 1;
IsoImageFilesystem *fs = NULL;
IsoDataSource *src = NULL;
IsoFileSource *root = NULL;
IsoReadOpts *ropts = NULL;
if (argc != 2) {
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", "");
result = iso_data_source_new_from_file(argv[1], &src);
if (result < 0) {
printf ("Error creating data source\n");
return 1;
demo_report_iso_err(result, "Error creating data source");
goto ex;
}
result = iso_read_opts_new(&ropts, 0);
if (result < 0) {
fprintf(stderr, "Error creating read options\n");
return 1;
demo_report_iso_err(result, "Error creating read options");
goto ex;
}
result = iso_image_filesystem_new(src, ropts, 1, &fs);
iso_read_opts_free(ropts);
if (result < 0) {
printf ("Error creating filesystem\n");
return 1;
demo_report_iso_err(result, "Error creating filesystem");
goto ex;
}
iso_read_opts_free(ropts);
ropts = NULL;
printf("\nVOLUME INFORMATION\n");
printf("==================\n\n");
@ -542,18 +548,27 @@ int gesture_iso_read(int argc, char **argv)
result = fs->get_root(fs, &root);
if (result < 0) {
printf ("Can't get root %d\n", result);
return 1;
demo_report_iso_err(result, "Cannot get root object");
goto ex;
}
/* iso_read_print_file_src(root); */
iso_read_print_dir(root, 0);
iso_file_source_unref(root);
fs->close(fs);
iso_filesystem_unref((IsoFilesystem*)fs);
iso_data_source_unref(src);
iso_finish();
return 0;
return_val = 0;
ex:;
if (root != NULL)
iso_file_source_unref(root);
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;
}