From: Daan De Meyer Date: Thu, 24 Nov 2022 09:07:32 +0000 (+0100) Subject: repart: Make sure we cleanup image file on failure if we create it X-Git-Tag: v253-rc1~344^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db1d4e6b9734691c3ec02045462b9ed9ce5d2777;p=thirdparty%2Fsystemd.git repart: Make sure we cleanup image file on failure if we create it --- diff --git a/src/partition/repart.c b/src/partition/repart.c index e3d9e4f6610..30de655c2bf 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -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);