diff --git a/core/rust/utils/src/account.rs b/core/rust/utils/src/account.rs index 496aa3a30..8cac3e4c1 100644 --- a/core/rust/utils/src/account.rs +++ b/core/rust/utils/src/account.rs @@ -105,10 +105,19 @@ pub fn close_account_raw<'a>( src_account_info: &AccountInfo<'a>, ) -> ProgramResult { let dest_starting_lamports = dest_account_info.lamports(); - **dest_account_info.lamports.borrow_mut() = dest_starting_lamports + let mut dest_lamports_mut = dest_account_info + .lamports + .try_borrow_mut() + .map_err(|_| ProgramError::AccountBorrowFailed)?; + **dest_lamports_mut = dest_starting_lamports .checked_add(src_account_info.lamports()) .ok_or(ProgramError::InvalidRealloc)?; - **src_account_info.lamports.borrow_mut() = 0; + + let mut src_lamports_mut = src_account_info + .lamports + .try_borrow_mut() + .map_err(|_| ProgramError::AccountBorrowFailed)?; + **src_lamports_mut = 0; src_account_info.assign(&system_program::ID); src_account_info.realloc(0, false).map_err(Into::into)