From 2b5802b273f214fd8a78d8da51f335949e4a5ad3 Mon Sep 17 00:00:00 2001 From: Sunny Titus Date: Tue, 16 Jul 2024 17:45:18 +0200 Subject: [PATCH 1/4] Fix memory leaks related to the MemoryStore --- src/Utilities/Memory/MemoryContainerIterator.f90 | 4 ++-- src/Utilities/Memory/MemoryManagerExt.f90 | 1 + src/Utilities/Memory/MemoryStore.f90 | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Utilities/Memory/MemoryContainerIterator.f90 b/src/Utilities/Memory/MemoryContainerIterator.f90 index bad175bf602..f9169a1d35a 100644 --- a/src/Utilities/Memory/MemoryContainerIterator.f90 +++ b/src/Utilities/Memory/MemoryContainerIterator.f90 @@ -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 diff --git a/src/Utilities/Memory/MemoryManagerExt.f90 b/src/Utilities/Memory/MemoryManagerExt.f90 index 00d61b7ebe7..f532586c7e7 100644 --- a/src/Utilities/Memory/MemoryManagerExt.f90 +++ b/src/Utilities/Memory/MemoryManagerExt.f90 @@ -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 diff --git a/src/Utilities/Memory/MemoryStore.f90 b/src/Utilities/Memory/MemoryStore.f90 index 4a7664770af..12a3ebd3ed3 100644 --- a/src/Utilities/Memory/MemoryStore.f90 +++ b/src/Utilities/Memory/MemoryStore.f90 @@ -31,7 +31,7 @@ function iterator(this) result(itr) class(MemoryStoreType) :: this type(MemoryContainerIteratorType) :: itr - itr = MemoryContainerIteratorType(this%container%Iterator()) + itr = MemoryContainerIteratorType(this%container%iterator()) end function !> @brief Add a MemoryType to the container From 7e6ad2fc080599cf518b8e2dd1f9b8187d46d5f4 Mon Sep 17 00:00:00 2001 From: Sunny Titus Date: Tue, 16 Jul 2024 17:58:36 +0200 Subject: [PATCH 2/4] Fix formatting error --- src/Utilities/Memory/MemoryManagerExt.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utilities/Memory/MemoryManagerExt.f90 b/src/Utilities/Memory/MemoryManagerExt.f90 index f532586c7e7..255c745e738 100644 --- a/src/Utilities/Memory/MemoryManagerExt.f90 +++ b/src/Utilities/Memory/MemoryManagerExt.f90 @@ -46,7 +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) + deallocate (itr) exit end if end do From 7fc58595060b4071e9a7b9057eb94234c5962f02 Mon Sep 17 00:00:00 2001 From: Sunny Titus Date: Wed, 17 Jul 2024 14:08:58 +0200 Subject: [PATCH 3/4] Fix failing ifort build --- src/Utilities/Memory/MemoryStore.f90 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Utilities/Memory/MemoryStore.f90 b/src/Utilities/Memory/MemoryStore.f90 index 12a3ebd3ed3..c5b11ce282f 100644 --- a/src/Utilities/Memory/MemoryStore.f90 +++ b/src/Utilities/Memory/MemoryStore.f90 @@ -12,7 +12,7 @@ module MemoryStoreModule type :: MemoryStoreType private - type(PtrHashTableType), private :: container + type(PtrHashTableType) :: container contains procedure :: iterator procedure :: add @@ -27,11 +27,13 @@ module MemoryStoreModule !! !< function iterator(this) result(itr) - ! -- dummy class(MemoryStoreType) :: this type(MemoryContainerIteratorType) :: itr - - itr = MemoryContainerIteratorType(this%container%iterator()) + ! -- local + class(IteratorType), allocatable :: container_iterator + + allocate(container_iterator, source=this%container%iterator()) + itr = MemoryContainerIteratorType(container_iterator) end function !> @brief Add a MemoryType to the container From 1ceb25e23cf32cbc3c35af3bdee7867fd930b94b Mon Sep 17 00:00:00 2001 From: Sunny Titus Date: Wed, 17 Jul 2024 14:11:46 +0200 Subject: [PATCH 4/4] Fix formatting error --- src/Utilities/Memory/MemoryStore.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utilities/Memory/MemoryStore.f90 b/src/Utilities/Memory/MemoryStore.f90 index c5b11ce282f..93a7a40e6fc 100644 --- a/src/Utilities/Memory/MemoryStore.f90 +++ b/src/Utilities/Memory/MemoryStore.f90 @@ -31,8 +31,8 @@ function iterator(this) result(itr) type(MemoryContainerIteratorType) :: itr ! -- local class(IteratorType), allocatable :: container_iterator - - allocate(container_iterator, source=this%container%iterator()) + + allocate (container_iterator, source=this%container%iterator()) itr = MemoryContainerIteratorType(container_iterator) end function