Add some error handling to oxfstool format and fix a couple of memory leaks

This commit is contained in:
2016-07-09 11:33:47 -05:00
parent 1bca0c46a7
commit 10290faf49
+14 -3
View File
@@ -79,6 +79,11 @@ int format(int argc, char **args) {
printf("Size: %llu bytes\n", size);
printf("Type: %d\n", type);
if (size < sizeof(FileStore64)) {
err = 1;
}
if (err) {
// format
switch (type) {
case 16:
@@ -90,19 +95,25 @@ int format(int argc, char **args) {
case 64:
FileStore64::format(buff, size, ox::fs::OxFS_64);
break;
default:
err = 1;
}
createFileSystem(buff);
if (err) {
auto file = fopen(path, "wb");
if (file) {
fwrite(buff, size, 1, file);
err = fclose(file);
err = fwrite(buff, size, 1, file);
err |= fclose(file);
if (err) {
printf("Could not write to file: %s.\n", path);
}
} else {
printf("Could not open file: %s.\n", path);
}
}
}
free(buff);
if (err == 0) {
printf("Created file system %s\n", path);