Skip to content

Commit

Permalink
forget to clean allocations and pages with data after exit/terminate
Browse files Browse the repository at this point in the history
  • Loading branch information
grishasobol committed Jun 24, 2024
1 parent 833679e commit c574115
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion common/src/program_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ pub trait ProgramStorage {
});
}

fn clear_pages_with_data(program_id: ProgramId) {
Self::PagesWithDataMap::remove(program_id);
}

fn allocations(program_id: ProgramId) -> Option<IntervalsTree<WasmPage>> {
Self::AllocationsMap::get(&program_id)
}
Expand All @@ -154,6 +158,10 @@ pub trait ProgramStorage {
Self::AllocationsMap::insert(program_id, allocations);
}

fn clear_allocations(program_id: ProgramId) {
Self::AllocationsMap::remove(program_id);
}

fn memory_infix(program_id: ProgramId) -> Option<MemoryInfix> {
match Self::ProgramMap::get(&program_id) {
Some(Program::Active(program)) => Some(program.memory_infix),
Expand Down Expand Up @@ -219,7 +227,7 @@ pub trait ProgramStorage {
}

/// Remove all memory page buffers under the given keys `program_id` and `memory_infix`.
fn remove_program_pages(program_id: ProgramId, memory_infix: MemoryInfix) {
fn clear_program_memory(program_id: ProgramId, memory_infix: MemoryInfix) {
Self::MemoryPageMap::clear_prefix(program_id, memory_infix);
}

Expand Down
4 changes: 3 additions & 1 deletion pallets/gear/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ where
memory_infix: MemoryInfix,
value_destination: ProgramId,
) {
ProgramStorageOf::<T>::remove_program_pages(program_id, memory_infix);
ProgramStorageOf::<T>::clear_allocations(program_id);
ProgramStorageOf::<T>::clear_pages_with_data(program_id);
ProgramStorageOf::<T>::clear_program_memory(program_id, memory_infix);

let program_account = program_id.cast();
let balance = CurrencyOf::<T>::free_balance(&program_account);
Expand Down

0 comments on commit c574115

Please sign in to comment.