From 02b33bb70118490777c29c84a4d304388feaacc0 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sun, 28 Jul 2024 09:34:13 +0000 Subject: [PATCH] VoteState::deserialize_into: drop previous collections before deserializing --- sdk/program/src/vote/state/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/program/src/vote/state/mod.rs b/sdk/program/src/vote/state/mod.rs index 1fea6d1a4dbcbe..6730890593acaf 100644 --- a/sdk/program/src/vote/state/mod.rs +++ b/sdk/program/src/vote/state/mod.rs @@ -487,6 +487,11 @@ impl VoteState { input: &[u8], vote_state: &mut VoteState, ) -> Result<(), InstructionError> { + // assign empty collections to drop() old allocations if any + vote_state.votes = VecDeque::new(); + vote_state.authorized_voters = AuthorizedVoters::default(); + vote_state.epoch_credits = Vec::new(); + VoteState::deserialize_into_ptr(input, vote_state as *mut VoteState) }