From ac1e1b5fd7effb0925b3131290c3b5fab282bdaa Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 11 Sep 2022 23:08:25 +0900 Subject: [PATCH] dissect-image: take reference of DecryptedImage into DissectedImage No functional changes. Preparation for later commits. --- src/shared/dissect-image.c | 12 ++++++++++-- src/shared/dissect-image.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 5e1af80997..e97c22d796 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1112,9 +1112,14 @@ DissectedImage* dissected_image_unref(DissectedImage *m) { if (!m) return NULL; + /* First, clear dissected partitions. */ for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) dissected_partition_done(m->partitions + i); + /* Second, free decrypted images. This must be after dissected_partition_done(), as freeing + * DecryptedImage may try to deactivate partitions. */ + decrypted_image_unref(m->decrypted_image); + free(m->image_name); free(m->hostname); strv_free(m->machine_info); @@ -2096,7 +2101,8 @@ int dissected_image_decrypt( return -EINVAL; if (!m->encrypted && !m->verity_ready) { - *ret = NULL; + if (ret) + *ret = NULL; return 0; } @@ -2130,7 +2136,9 @@ int dissected_image_decrypt( } } - *ret = TAKE_PTR(d); + m->decrypted_image = TAKE_PTR(d); + if (ret) + *ret = decrypted_image_ref(m->decrypted_image); return 1; #else diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 6dd5246042..7308798493 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -211,6 +211,7 @@ struct DissectedImage { bool single_file_system:1; /* MBR/GPT or single file system */ DissectedPartition partitions[_PARTITION_DESIGNATOR_MAX]; + DecryptedImage *decrypted_image; /* Meta information extracted from /etc/os-release and similar */ char *image_name;