This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 7b18f5eb6f3af2dad5ef714e07b22181e22f3870
Author: Ville Juven <ville.ju...@unikie.com>
AuthorDate: Wed Sep 27 15:04:59 2023 +0300

    risc-v/riscv_addrenv.c: Fix bug where SHM area page tables are not freed
    
    The SHM physically backed memory does not belong to the user process,
    but the page table containing the mapping does -> delete the page table
    memory regardless.
---
 arch/risc-v/src/common/riscv_addrenv.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

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);
             }

Reply via email to