diff --git a/arch/risc-v/src/common/riscv_addrenv.c b/arch/risc-v/src/common/riscv_addrenv.c index 685dea744e..cb49c1a51d 100644 --- a/arch/risc-v/src/common/riscv_addrenv.c +++ b/arch/risc-v/src/common/riscv_addrenv.c @@ -535,28 +535,24 @@ int up_addrenv_destroy(arch_addrenv_t *addrenv) { for (i = 0; i < ENTRIES_PER_PGT; i++, vaddr += pgsize) { - if (vaddr_is_shm(vaddr)) - { - /* Do not free memory from SHM area */ - - continue; - } - ptlast = (uintptr_t *)riscv_pgvaddr(mmu_pte_to_paddr(ptprev[i])); if (ptlast) { - /* Page table allocated, free any allocated memory */ - - for (j = 0; j < ENTRIES_PER_PGT; j++) + if (!vaddr_is_shm(vaddr)) { - paddr = mmu_pte_to_paddr(ptlast[j]); - if (paddr) + /* Free the allocated pages, but not from SHM area */ + + for (j = 0; j < ENTRIES_PER_PGT; j++) { - mm_pgfree(paddr, 1); + paddr = mmu_pte_to_paddr(ptlast[j]); + if (paddr) + { + mm_pgfree(paddr, 1); + } } } - /* Then free the page table itself */ + /* Regardless, free the page table itself */ mm_pgfree((uintptr_t)ptlast, 1); }