From: Yu Watanabe Date: Sun, 11 Sep 2022 14:08:25 +0000 (+0900) Subject: dissect-image: take reference of DecryptedImage into DissectedImage X-Git-Tag: v252-rc1~152^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ac1e1b5fd7effb0925b3131290c3b5fab282bdaa;p=thirdparty%2Fsystemd.git dissect-image: take reference of DecryptedImage into DissectedImage No functional changes. Preparation for later commits. --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 5e1af809975..e97c22d7964 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 6dd52460426..7308798493b 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;