Skip to content

Commit 48683f7

Browse files
onikombroz
authored andcommitted
Fix memory leak on error path in luksAddKey.
1 parent e48d5b6 commit 48683f7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/cryptsetup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ static int action_luksAddKey(void)
22492249
{
22502250
bool pin_provided = false;
22512251
int keyslot_old, keyslot_new, keysize = 0, r = -EINVAL;
2252-
char *key = NULL, *password = NULL, *vk_description = NULL;
2252+
char *key, *vk_description, *password = NULL;
22532253
size_t password_size = 0;
22542254
struct crypt_device *cd = NULL;
22552255
struct crypt_keyslot_context *p_kc_new = NULL, *kc = NULL, *kc_new = NULL;
@@ -2325,8 +2325,10 @@ static int action_luksAddKey(void)
23252325
if (r == -EPERM)
23262326
log_err(_("Volume key does not match the volume."));
23272327
check_signal(&r);
2328-
if (r < 0)
2328+
if (r < 0) {
2329+
crypt_safe_free(key);
23292330
goto out;
2331+
}
23302332
r = crypt_keyslot_context_init_by_volume_key(cd, key, keysize, &kc);
23312333
crypt_safe_free(key);
23322334
} else if (ARG_SET(OPT_VOLUME_KEY_KEYRING_ID)) {

0 commit comments

Comments
 (0)