Add some error handling to oxfstool format and fix a couple of memory leaks
This commit is contained in:
+14
-3
@@ -79,6 +79,11 @@ int format(int argc, char **args) {
|
|||||||
printf("Size: %llu bytes\n", size);
|
printf("Size: %llu bytes\n", size);
|
||||||
printf("Type: %d\n", type);
|
printf("Type: %d\n", type);
|
||||||
|
|
||||||
|
if (size < sizeof(FileStore64)) {
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err) {
|
||||||
// format
|
// format
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 16:
|
case 16:
|
||||||
@@ -90,19 +95,25 @@ int format(int argc, char **args) {
|
|||||||
case 64:
|
case 64:
|
||||||
FileStore64::format(buff, size, ox::fs::OxFS_64);
|
FileStore64::format(buff, size, ox::fs::OxFS_64);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
err = 1;
|
||||||
}
|
}
|
||||||
createFileSystem(buff);
|
|
||||||
|
|
||||||
|
if (err) {
|
||||||
auto file = fopen(path, "wb");
|
auto file = fopen(path, "wb");
|
||||||
if (file) {
|
if (file) {
|
||||||
fwrite(buff, size, 1, file);
|
err = fwrite(buff, size, 1, file);
|
||||||
err = fclose(file);
|
err |= fclose(file);
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("Could not write to file: %s.\n", path);
|
printf("Could not write to file: %s.\n", path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("Could not open file: %s.\n", path);
|
printf("Could not open file: %s.\n", path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buff);
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
printf("Created file system %s\n", path);
|
printf("Created file system %s\n", path);
|
||||||
|
|||||||
Reference in New Issue
Block a user