From 69f8c3537528c705289e0e24181016edb90ab93f Mon Sep 17 00:00:00 2001 From: Stefano Zaghi Date: Thu, 20 Apr 2017 12:44:21 +0200 Subject: [PATCH] Refactor all source-allocations Refactor all source-allocations by mold-allocations and assigments. Why: Soucer-allocation generates memory leaks that must be avoided. Hopefully, mold-allocation/assignment should not. Side effects: Nothing (apparently), memory leaks occurences must still be checked. --- .../factories/wenoof_interpolator_factory.f90 | 12 ++++++++---- src/lib/factories/wenoof_kappa_factory.f90 | 3 ++- src/lib/factories/wenoof_weights_factory.f90 | 18 ++++++++++++------ src/tests/wenoof_test_linear_advection.f90 | 3 ++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/lib/factories/wenoof_interpolator_factory.f90 b/src/lib/factories/wenoof_interpolator_factory.f90 index e90ee74..2f9fe0d 100644 --- a/src/lib/factories/wenoof_interpolator_factory.f90 +++ b/src/lib/factories/wenoof_interpolator_factory.f90 @@ -60,11 +60,15 @@ subroutine create_constructor(interpolator_type, S, interpolations_constructor, call constructor%create(S=S) select type(constructor) type is(interpolator_js_constructor) - allocate(constructor%interpolations_constructor, source=interpolations_constructor) - allocate(constructor%weights_constructor, source=weights_constructor) + allocate(constructor%interpolations_constructor, mold=interpolations_constructor) + constructor%interpolations_constructor = interpolations_constructor + allocate(constructor%weights_constructor, mold=weights_constructor) + constructor%weights_constructor = weights_constructor type is(reconstructor_js_constructor) - allocate(constructor%interpolations_constructor, source=interpolations_constructor) - allocate(constructor%weights_constructor, source=weights_constructor) + allocate(constructor%interpolations_constructor, mold=interpolations_constructor) + constructor%interpolations_constructor = interpolations_constructor + allocate(constructor%weights_constructor, mold=weights_constructor) + constructor%weights_constructor = weights_constructor endselect endsubroutine create_constructor endmodule wenoof_interpolator_factory diff --git a/src/lib/factories/wenoof_kappa_factory.f90 b/src/lib/factories/wenoof_kappa_factory.f90 index d06a3d9..1c6a634 100644 --- a/src/lib/factories/wenoof_kappa_factory.f90 +++ b/src/lib/factories/wenoof_kappa_factory.f90 @@ -65,7 +65,8 @@ subroutine create_constructor_int(interpolator_type, S, stencil, x_target, inter constructor%stencil = stencil constructor%x_target = x_target call constructor%create(S=S) - allocate(constructor%interpolations_constructor, source=interpolations_constructor) + allocate(constructor%interpolations_constructor, mold=interpolations_constructor) + constructor%interpolations_constructor = interpolations_constructor endselect endsubroutine create_constructor_int endmodule wenoof_kappa_factory diff --git a/src/lib/factories/wenoof_weights_factory.f90 b/src/lib/factories/wenoof_weights_factory.f90 index 26758c1..ced46b8 100644 --- a/src/lib/factories/wenoof_weights_factory.f90 +++ b/src/lib/factories/wenoof_weights_factory.f90 @@ -74,13 +74,19 @@ subroutine create_constructor(interpolator_type, S, alpha_constructor, beta_cons call constructor%create(S=S) select type(constructor) type is(weights_int_js_constructor) - allocate(constructor%alpha_constructor, source=alpha_constructor) - allocate(constructor%beta_constructor, source=beta_constructor) - allocate(constructor%kappa_constructor, source=kappa_constructor) + allocate(constructor%alpha_constructor, mold=alpha_constructor) + constructor%alpha_constructor = alpha_constructor + allocate(constructor%beta_constructor, mold=beta_constructor) + constructor%beta_constructor = beta_constructor + allocate(constructor%kappa_constructor, mold=kappa_constructor) + constructor%kappa_constructor = kappa_constructor type is(weights_rec_js_constructor) - allocate(constructor%alpha_constructor, source=alpha_constructor) - allocate(constructor%beta_constructor, source=beta_constructor) - allocate(constructor%kappa_constructor, source=kappa_constructor) + allocate(constructor%alpha_constructor, mold=alpha_constructor) + constructor%alpha_constructor = alpha_constructor + allocate(constructor%beta_constructor, mold=beta_constructor) + constructor%beta_constructor = beta_constructor + allocate(constructor%kappa_constructor, mold=kappa_constructor) + constructor%kappa_constructor = kappa_constructor endselect endsubroutine create_constructor endmodule wenoof_weights_factory diff --git a/src/tests/wenoof_test_linear_advection.f90 b/src/tests/wenoof_test_linear_advection.f90 index 8812341..59acc79 100644 --- a/src/tests/wenoof_test_linear_advection.f90 +++ b/src/tests/wenoof_test_linear_advection.f90 @@ -328,7 +328,8 @@ subroutine advection_assign_advection(lhs, rhs) if (allocated(rhs%BC_R)) lhs%BC_R = rhs%BC_R if (allocated(rhs%interpolator)) then if (allocated(lhs%interpolator)) deallocate(lhs%interpolator) - allocate(lhs%interpolator, source=rhs%interpolator) + allocate(lhs%interpolator, mold=rhs%interpolator) + lhs%interpolator = rhs%interpolator endif endselect endsubroutine advection_assign_advection