diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -65,31 +65,37 @@ startwizard: error = geom_gettree(&mesh); + if (error != 0) + return (1); bsddialog_backtitle(&conf, "FreeBSD Installer"); - error = geom_gettree(&mesh); disk = boot_disk_select(&mesh); - if (disk == NULL) + if (disk == NULL) { + geom_deletetree(&mesh); return (1); + } bsddialog_clearterminal(); bsddialog_backtitle(&conf, "FreeBSD Installer"); schemeroot = wizard_partition(&mesh, disk); free(disk); + geom_deletetree(&mesh); if (schemeroot == NULL) return (1); - geom_deletetree(&mesh); bsddialog_clearterminal(); bsddialog_backtitle(&conf, "FreeBSD Installer"); error = geom_gettree(&mesh); + if (error != 0) { + free(schemeroot); + return (1); + } error = wizard_makeparts(&mesh, schemeroot, fstype, 1); - if (error) - goto startwizard; free(schemeroot); - geom_deletetree(&mesh); + if (error) + goto startwizard; return (0); } @@ -310,11 +316,13 @@ if (strcmp(scheme, "MBR") == 0) { struct gmesh submesh; - geom_gettree(&submesh); - gpart_create(provider_for_name(&submesh, disk), - "freebsd", NULL, NULL, &retval, - choice /* Non-interactive for "Entire Disk" */); - geom_deletetree(&submesh); + + if (geom_gettree(&submesh) == 0) { + gpart_create(provider_for_name(&submesh, disk), + "freebsd", NULL, NULL, &retval, + choice /* Non-interactive for "Entire Disk" */); + geom_deletetree(&submesh); + } } else { retval = strdup(disk); } @@ -334,7 +342,7 @@ struct gmesh submesh; char swapsizestr[10], rootsizestr[10]; intmax_t swapsize, available; - int retval; + int error, retval; struct bsddialog_conf conf; if (strcmp(fstype, "zfs") == 0) { @@ -381,12 +389,16 @@ humanize_number(rootsizestr, 7, available - swapsize - 1024*1024, "B", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); - geom_gettree(&submesh); + error = geom_gettree(&submesh); + if (error != 0) + return (error); pp = provider_for_name(&submesh, disk); gpart_create(pp, fsname, rootsizestr, "/", NULL, 0); geom_deletetree(&submesh); - geom_gettree(&submesh); + error = geom_gettree(&submesh); + if (error != 0) + return (error); pp = provider_for_name(&submesh, disk); gpart_create(pp, "freebsd-swap", swapsizestr, NULL, NULL, 0); geom_deletetree(&submesh); diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -63,9 +63,10 @@ struct gmesh mesh; /* Revert all changes and exit dialog-mode cleanly on SIGINT */ - geom_gettree(&mesh); - gpart_revert_all(&mesh); - geom_deletetree(&mesh); + if (geom_gettree(&mesh) == 0) { + gpart_revert_all(&mesh); + geom_deletetree(&mesh); + } bsddialog_end(); @@ -216,16 +217,17 @@ if (prompt == NULL) { error = geom_gettree(&mesh); - if (validate_setup()) { - error = apply_changes(&mesh); - } else { - gpart_revert_all(&mesh); - error = -1; + if (error != 0) { + if (validate_setup()) { + error = apply_changes(&mesh); + } else { + gpart_revert_all(&mesh); + error = -1; + } + geom_deletetree(&mesh); } } - geom_deletetree(&mesh); - free(items); bsddialog_end(); return (error); diff --git a/usr.sbin/bsdinstall/partedit/scripted.c b/usr.sbin/bsdinstall/partedit/scripted.c --- a/usr.sbin/bsdinstall/partedit/scripted.c +++ b/usr.sbin/bsdinstall/partedit/scripted.c @@ -76,6 +76,8 @@ scheme = default_scheme(); error = geom_gettree(&mesh); + if (error != 0) + return (-1); if (provider_for_name(&mesh, disk) == NULL) { fprintf(stderr, "GEOM provider %s not found\n", disk); geom_deletetree(&mesh); @@ -97,16 +99,22 @@ if (strcmp(scheme, "MBR") == 0) { struct gmesh submesh; - geom_gettree(&submesh); - gpart_create(provider_for_name(&submesh, disk), - "freebsd", NULL, NULL, &disk, 0); - geom_deletetree(&submesh); + + if (geom_gettree(&submesh) == 0) { + gpart_create(provider_for_name(&submesh, disk), + "freebsd", NULL, NULL, &disk, 0); + geom_deletetree(&submesh); + } } else { - disk= strdup(disk); + disk = strdup(disk); } geom_deletetree(&mesh); error = geom_gettree(&mesh); + if (error != 0) { + free(disk); + return (-1); + } /* Create partitions */ if (config == NULL) { @@ -133,6 +141,10 @@ NULL, 0); geom_deletetree(&mesh); error = geom_gettree(&mesh); + if (error != 0) { + free(disk); + return (-1); + } size = type = mount = NULL; } @@ -143,8 +155,8 @@ return (0); } -static -int parse_disk_config(char *input) +static int +parse_disk_config(char *input) { char *ap; char *disk = NULL, *scheme = NULL, *partconfig = NULL; @@ -184,9 +196,11 @@ if (disk == NULL || strcmp(disk, "DEFAULT") == 0) { struct gmesh mesh; - geom_gettree(&mesh); - disk = boot_disk_select(&mesh); - geom_deletetree(&mesh); + + if (geom_gettree(&mesh) == 0) { + disk = boot_disk_select(&mesh); + geom_deletetree(&mesh); + } } return (part_config(disk, scheme, partconfig));