diff --git a/services/pddb/src/backend/basis.rs b/services/pddb/src/backend/basis.rs index 82238de11..b538e281b 100644 --- a/services/pddb/src/backend/basis.rs +++ b/services/pddb/src/backend/basis.rs @@ -572,7 +572,11 @@ impl BasisCache { // this implementation is still in progress dict_entry.key_erase(key); } + // sync the key pools to disk + if !dict_entry.sync_small_pool(hw, &mut basis.v2p_map, &basis.cipher) { + return Err(Error::new(ErrorKind::OutOfMemory, "Ran out of memory syncing small pool")); + } dict_entry.sync_large_pool(); // encrypt and write the dict entry to disk basis.dict_sync(hw, dict)?; @@ -1697,6 +1701,13 @@ impl BasisCacheEntry { } } for dict in dictnames { + if let Some(dict_entry) = self.dicts.get_mut(&dict) { + if !dict_entry.sync_small_pool(hw, &mut self.v2p_map, &self.cipher) { + return Err(Error::new(ErrorKind::OutOfMemory, "Ran out of memory syncing small pool")); + } + dict_entry.sync_large_pool(); + } + match self.dict_sync(hw, &dict) { Ok(_) => {}, Err(e) => { diff --git a/services/pddb/src/backend/dictionary.rs b/services/pddb/src/backend/dictionary.rs index 9fcbc094d..b2eae3e35 100644 --- a/services/pddb/src/backend/dictionary.rs +++ b/services/pddb/src/backend/dictionary.rs @@ -307,6 +307,10 @@ impl DictCacheEntry { fn try_fill_small_key(&mut self, hw: &mut PddbOs, v2p_map: &HashMap::, cipher: &Aes256GcmSiv, data_cache: &mut PlaintextCache, key_name: &str) { if let Some(kcache) = self.keys.get_mut(key_name) { + if !kcache.flags.valid() { + // nothing to fill, the key entry isn't valid + return; + } if let Some(pool_index) = small_storage_index_from_key(&kcache, self.index) { // if the key is within the small pool space, create a bookkeeping record for it, and pre-cache its data. // generate the index within the small pool based on the address @@ -1014,7 +1018,8 @@ impl DictCacheEntry { log::error!("Double-free error in free_keys()"); log::info!("free_key_vec[i].0: {:?}", free_key_vec[i].0); log::info!("index: {}", index); - panic!("Double-free error in free_keys()"); + panic!("Double-free error in free_keys(). free_key_vec[i].0: {:?}, index: {}, free_key_vec.len(): {}", + free_key_vec[i].0, index, free_key_vec.len()); } FreeKeyCases::RightAdjacent => { // see if we should merge to the right