From 5d7383cf7c3c7e026750d60dd40d823b508e290e Mon Sep 17 00:00:00 2001 From: Tom Caputi Date: Tue, 16 Feb 2016 14:24:35 -0500 Subject: [PATCH] fixed bug where zap_cursor_fini() wasn't being called in dsl_keychain_open() if an error occured during the loop. --- cmd/zfs/zfs_main.c | 8 ++++---- module/zfs/dsl_keychain.c | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 4452bcdc56ca..e89385a9cd74 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -6715,7 +6715,7 @@ zfs_do_crypto(int argc, char **argv) boolean_t load = B_FALSE, unload = B_FALSE; boolean_t add_key = B_FALSE, rewrap = B_FALSE; nvlist_t *props = NULL; - zfs_handle_t *zhp; + zfs_handle_t *zhp = NULL; if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) nomem(); @@ -6804,8 +6804,7 @@ zfs_do_crypto(int argc, char **argv) if (ret) goto error; - if (props) - nvlist_free(props); + nvlist_free(props); zfs_close(zhp); return (0); @@ -6815,7 +6814,8 @@ zfs_do_crypto(int argc, char **argv) error: if (props) nvlist_free(props); - zfs_close(zhp); + if (zhp) + zfs_close(zhp); return (-1); } diff --git a/module/zfs/dsl_keychain.c b/module/zfs/dsl_keychain.c index 41c99c38b381..50b0c610d60a 100644 --- a/module/zfs/dsl_keychain.c +++ b/module/zfs/dsl_keychain.c @@ -396,7 +396,7 @@ dsl_keychain_free(dsl_keychain_t *kc) { dsl_keychain_entry_t *kce; - VERIFY0(refcount_count(&kc->kc_refcnt)); + ASSERT(refcount_count(&kc->kc_refcnt) == 0); /* release each encryption key from the keychain */ while ((kce = list_head(&kc->kc_entries)) != NULL) { @@ -458,7 +458,7 @@ dsl_keychain_open(objset_t *mos, dsl_wrapping_key_t *wkey, sizeof (dsl_crypto_key_phys_t), &dckp); if (ret) { ret = SET_ERROR(EIO); - goto error; + goto error_fini; } /* all crypts should match */ @@ -476,21 +476,21 @@ dsl_keychain_open(objset_t *mos, dsl_wrapping_key_t *wkey, ret = zio_crypt_key_unwrap(wkey, crypt, &dckp, keydata); if (ret) { ret = SET_ERROR(EINVAL); - goto error; + goto error_fini; } /* allocate an initialize a keychain entry */ kce = kmem_zalloc(sizeof (dsl_keychain_entry_t), KM_SLEEP); if (!kce) { ret = SET_ERROR(ENOMEM); - goto error; + goto error_fini; } list_link_init(&kce->ke_link); kce->ke_txgid = txgid; ret = zio_crypt_key_init(crypt, keydata, &kce->ke_key); if (ret) - goto error; + goto error_fini; /* * the zap does not store keys in order, @@ -525,6 +525,8 @@ dsl_keychain_open(objset_t *mos, dsl_wrapping_key_t *wkey, *kc_out = kc; return (0); +error_fini: + zap_cursor_fini(&zc); error: LOG_ERROR(ret, ""); if (kce)