From 07dfd2e0ba90590b92a85b21e131263e3496e548 Mon Sep 17 00:00:00 2001 From: Kyle <kyle.c.klenk@gmail.com> Date: Wed, 30 Nov 2022 17:37:47 +0000 Subject: [PATCH] fixed memroy leak --- .../file_access_actor/output_container.hpp | 5 ++++- .../cpp_code/file_access_actor.cpp | 15 ++++++++++----- .../actors/hru_actor/cpp_code/hru_actor.cpp | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/build/includes/file_access_actor/output_container.hpp b/build/includes/file_access_actor/output_container.hpp index 9b598fe..d5fdb89 100644 --- a/build/includes/file_access_actor/output_container.hpp +++ b/build/includes/file_access_actor/output_container.hpp @@ -38,6 +38,7 @@ struct hru_output_handles { void* handle_output_timestep = new_handle_var_i(); ~hru_output_handles() { + std::cout << "Destructor called" << std::endl; // statistics structures delete_handle_var_dlength(handle_forc_stat); delete_handle_var_dlength(handle_prog_stat); @@ -91,7 +92,9 @@ void initArrayOfOuputPartitions(std::vector<std::shared_ptr<output_partition>>& // Take a timestep of HRU data and add it to the output structure // If we need to write to a file then return the partition_index -std::optional<int> addHRUOutput(std::vector<std::shared_ptr<output_partition>>& output_partitions, caf::actor hru_actor, int gru_index, int hru_index, std::shared_ptr<hru_output_handles>& timestep_output); +std::optional<int> addHRUOutput(std::vector<std::shared_ptr<output_partition>>& output_partitions, + caf::actor hru_actor, int gru_index, int hru_index, + std::shared_ptr<hru_output_handles>& timestep_output); // find which partition the HRU belongs to int findPatritionIndex(int grus_per_partition, int gru_index, int num_partitions); diff --git a/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp b/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp index b7a197a..783b045 100644 --- a/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp +++ b/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp @@ -35,7 +35,13 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int start_gr initalizeFileAccessActor(self); - // Setup output container + + if (self->state.num_steps < self->state.file_access_actor_settings.num_timesteps_in_output_buffer) { + self->state.num_output_steps = self->state.num_steps; + self->state.file_access_actor_settings.num_timesteps_in_output_buffer = self->state.num_steps; + } + + // Setup output container initArrayOfOuputPartitions(self->state.output_partitions, self->state.file_access_actor_settings.num_partitions_in_output_buffer, self->state.num_gru, @@ -51,10 +57,7 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int start_gr std::shared_ptr<hru_output_handles> params = std::make_shared<hru_output_handles>(); self->state.file_access_timing.updateStartPoint("write_duration"); - params->handle_attr_struct = new_handle_var_d(); - params->handle_type_struct = new_handle_var_i(); - params->handle_mpar_struct = new_handle_var_dlength(); - params->handle_bpar_struct = new_handle_var_d(); + // populate the newly created Fortran structures set_var_d(attr_struct, params->handle_attr_struct); set_var_i(type_struct, params->handle_type_struct); @@ -175,6 +178,8 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int start_gr self->state.file_access_timing.updateStartPoint("write_duration"); + aout(self) << "Called\n"; + std::shared_ptr<hru_output_handles> hru_output = std::make_shared<hru_output_handles>(); int err = 0; diff --git a/build/source/actors/hru_actor/cpp_code/hru_actor.cpp b/build/source/actors/hru_actor/cpp_code/hru_actor.cpp index dba0995..098fbb4 100644 --- a/build/source/actors/hru_actor/cpp_code/hru_actor.cpp +++ b/build/source/actors/hru_actor/cpp_code/hru_actor.cpp @@ -171,7 +171,7 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, aout(self) << "Run Physics Duration = " << self->state.hru_timing.getDuration("run_physics_duration").value_or(-1.0) << " Seconds\n"; aout(self) << "Write Output Duration = " << self->state.hru_timing.getDuration("write_output_duration").value_or(-1.0) << " Seconds\n\n"; - self->send(self->state.file_access_actor, done_hru_v, self->state.indxGRU, self->state.indxHRU); + // self->send(self->state.file_access_actor, done_hru_v, self->state.indxGRU, self->state.indxHRU); self->send(self->state.parent, done_hru_v, -- GitLab