Skip to content

Commit

Permalink
fix(mem): address memory leak related to the MemoryStore (#1953)
Browse files Browse the repository at this point in the history
Fixes the memory leaks present in the PtrHashTableIterator and PtrHashTable
  • Loading branch information
Manangka authored Jul 23, 2024
1 parent c5da9b3 commit 0b493e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Utilities/Memory/MemoryContainerIterator.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ module MemoryContainerIteratorModule
!!
!<
function constructor(container_iterator) result(iterator)
class(IteratorType) :: container_iterator
class(IteratorType), allocatable :: container_iterator
type(MemoryContainerIteratorType) :: iterator

iterator%container_iterator = container_iterator
call move_alloc(container_iterator, iterator%container_iterator)

end function constructor

Expand Down
1 change: 1 addition & 0 deletions src/Utilities/Memory/MemoryManagerExt.f90
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ subroutine memorystore_remove(component, subcomponent, context)
if (mt%path == memory_path .and. mt%mt_associated()) then
call mt%mt_deallocate()
removed = .true.
deallocate (itr)
exit
end if
end do
Expand Down
8 changes: 5 additions & 3 deletions src/Utilities/Memory/MemoryStore.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module MemoryStoreModule

type :: MemoryStoreType
private
type(PtrHashTableType), private :: container
type(PtrHashTableType) :: container
contains
procedure :: iterator
procedure :: add
Expand All @@ -27,11 +27,13 @@ module MemoryStoreModule
!!
!<
function iterator(this) result(itr)
! -- dummy
class(MemoryStoreType) :: this
type(MemoryContainerIteratorType) :: itr
! -- local
class(IteratorType), allocatable :: container_iterator

itr = MemoryContainerIteratorType(this%container%Iterator())
allocate (container_iterator, source=this%container%iterator())
itr = MemoryContainerIteratorType(container_iterator)
end function

!> @brief Add a MemoryType to the container
Expand Down

0 comments on commit 0b493e0

Please sign in to comment.