repart: Make sure we cleanup image file on failure if we create it

This commit is contained in:
Daan De Meyer
2022-11-29 10:08:51 +01:00
parent 448cfb7f37
commit db1d4e6b97
+8 -1
View File
@@ -264,6 +264,7 @@ typedef struct Context {
sd_id128_t seed;
char *node;
bool node_is_our_file;
int backing_fd;
bool from_scratch;
@@ -472,7 +473,10 @@ static Context *context_free(Context *context) {
fdisk_unref_context(context->fdisk_context);
safe_close(context->backing_fd);
free(context->node);
if (context->node_is_our_file)
unlink_and_free(context->node);
else
free(context->node);
return mfree(context);
}
@@ -6040,6 +6044,7 @@ static int find_root(Context *context) {
return log_error_errno(errno, "Failed to create '%s': %m", arg_node);
context->node = TAKE_PTR(s);
context->node_is_our_file = true;
context->backing_fd = TAKE_FD(fd);
return 0;
}
@@ -6481,6 +6486,8 @@ static int run(int argc, char *argv[]) {
(void) context_dump(context, /*late=*/ true);
context->node = mfree(context->node);
LIST_FOREACH(partitions, p, context->partitions)
p->split_path = mfree(p->split_path);