Skip to content

Commit 520e448

Browse files
Fixing realloc to downsize an account. (#1188)
1 parent 3b9e6b8 commit 520e448

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/rust/utils/src/account.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ pub fn resize_or_reallocate_account_raw<'a>(
6666
) -> ProgramResult {
6767
let rent = Rent::get()?;
6868
let new_minimum_balance = rent.minimum_balance(new_size);
69-
let lamports_diff =
70-
new_minimum_balance.abs_diff(target_account.lamports());
69+
let lamports_diff = new_minimum_balance.abs_diff(target_account.lamports());
7170
if new_size == target_account.data_len() {
7271
return Ok(());
7372
}
@@ -89,10 +88,13 @@ pub fn resize_or_reallocate_account_raw<'a>(
8988
account_infos,
9089
)?;
9190
} else {
92-
(**target_account.try_borrow_mut_lamports()?)
91+
let target_account_lamports = target_account.lamports();
92+
(**target_account.try_borrow_mut_lamports()?) = target_account_lamports
9393
.checked_sub(lamports_diff)
9494
.ok_or(ProgramError::InvalidRealloc)?;
95-
(**funding_account.try_borrow_mut_lamports()?)
95+
96+
let funding_account_lamports = funding_account.lamports();
97+
(**funding_account.try_borrow_mut_lamports()?) = funding_account_lamports
9698
.checked_add(lamports_diff)
9799
.ok_or(ProgramError::InvalidRealloc)?;
98100
}

0 commit comments

Comments
 (0)