diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index f32a8fc7608..b7841a4c411 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -537,16 +537,16 @@ fil_parse_write_crypt_data( ptr += len; /* update fil_space memory cache with crypt_data */ - fil_space_t* space = fil_space_acquire_silent(space_id); - - if (space) { + if (fil_space_t* space = fil_space_acquire_silent(space_id)) { crypt_data = fil_space_set_crypt_data(space, crypt_data); fil_space_release(space); - } - - /* Check is used key found from encryption plugin */ - if (crypt_data->should_encrypt() && !crypt_data->is_key_found()) { - *err = DB_DECRYPTION_FAILED; + /* Check is used key found from encryption plugin */ + if (crypt_data->should_encrypt() + && !crypt_data->is_key_found()) { + *err = DB_DECRYPTION_FAILED; + } + } else { + fil_space_destroy_crypt_data(&crypt_data); } return ptr; diff --git a/storage/xtradb/fil/fil0crypt.cc b/storage/xtradb/fil/fil0crypt.cc index 8c388303070..bbafad6d04b 100644 --- a/storage/xtradb/fil/fil0crypt.cc +++ b/storage/xtradb/fil/fil0crypt.cc @@ -537,16 +537,16 @@ fil_parse_write_crypt_data( ptr += len; /* update fil_space memory cache with crypt_data */ - fil_space_t* space = fil_space_acquire_silent(space_id); - - if (space) { + if (fil_space_t* space = fil_space_acquire_silent(space_id)) { crypt_data = fil_space_set_crypt_data(space, crypt_data); fil_space_release(space); - } - - /* Check is used key found from encryption plugin */ - if (crypt_data->should_encrypt() && !crypt_data->is_key_found()) { - *err = DB_DECRYPTION_FAILED; + /* Check is used key found from encryption plugin */ + if (crypt_data->should_encrypt() + && !crypt_data->is_key_found()) { + *err = DB_DECRYPTION_FAILED; + } + } else { + fil_space_destroy_crypt_data(&crypt_data); } return ptr;