summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-16 20:24:26 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-17 21:57:10 +0200
commitcf610e1d873d6bf1a6017597ef50a6cf68f18313 (patch)
treeb630aec5445d0388fb052a0da960fd0f1dd6e94a
parentMerge pull request #24622 from yuwata/udev-open-with-noctty (diff)
downloadsystemd-cf610e1d873d6bf1a6017597ef50a6cf68f18313.tar.xz
systemd-cf610e1d873d6bf1a6017597ef50a6cf68f18313.zip
cryptsetup-util: introduce crypt_free_and_replace()
-rw-r--r--src/shared/cryptsetup-util.h5
-rw-r--r--src/shared/dissect-image.c3
2 files changed, 6 insertions, 2 deletions
diff --git a/src/shared/cryptsetup-util.h b/src/shared/cryptsetup-util.h
index fc80edb411..b1ce07ec8a 100644
--- a/src/shared/cryptsetup-util.h
+++ b/src/shared/cryptsetup-util.h
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include "alloc-util.h"
#include "json.h"
#include "macro.h"
@@ -69,6 +70,10 @@ int dlopen_cryptsetup(void);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct crypt_device *, crypt_free, NULL);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct crypt_device *, sym_crypt_free, NULL);
+/* Be careful, this works with dlopen_cryptsetup(), that is, it calls sym_crypt_free() instead of crypt_free(). */
+#define crypt_free_and_replace(a, b) \
+ free_and_replace_full(a, b, sym_crypt_free)
+
void cryptsetup_enable_logging(struct crypt_device *cd);
int cryptsetup_set_minimal_pbkdf(struct crypt_device *cd);
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 274c33c35e..5eaff64f87 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -2016,8 +2016,7 @@ static int verity_partition(
if (r < 0)
return r;
- sym_crypt_free(cd);
- cd = TAKE_PTR(existing_cd);
+ crypt_free_and_replace(cd, existing_cd);
}
}
if (r >= 0)