utils: add a generic mlock function with a destructor

Introduces a generic utility function to replace the repeated pattern of
sodium_mlock() + tal_add_destructor()
This commit is contained in:
Sangbida Chaudhuri
2025-10-24 13:57:50 +10:30
committed by Rusty Russell
parent 310405761a
commit 463712f3b7
7 changed files with 27 additions and 33 deletions

View File

@@ -223,9 +223,6 @@ static void encrypt_hsm(const char *hsm_secret_path)
if (!encrypt_legacy_hsm_secret(encryption_key, &legacy_secret, encrypted_hsm_secret))
errx(ERROR_LIBSODIUM, "Could not encrypt the hsm_secret seed.");
/* Securely discard the encryption key */
destroy_secret(encryption_key);
/* Create a backup file, "just in case". */
rename(hsm_secret_path, backup);
fd = open(hsm_secret_path, O_CREAT|O_EXCL|O_WRONLY, 0400);