Skip to content

Fix memory leaks in CHeatSolver#1256

Merged
maxaehle merged 13 commits intodevelopfrom
fix_memoryleaks_cheatsolver
Apr 14, 2021
Merged

Fix memory leaks in CHeatSolver#1256
maxaehle merged 13 commits intodevelopfrom
fix_memoryleaks_cheatsolver

Conversation

@maxaehle
Copy link
Contributor

@maxaehle maxaehle commented Apr 7, 2021

Proposed Changes

The following members of CHeatSolver were allocated but never freed: Primitive_Flow_i, Primitive_Flow_j, HeatFlux_per_Marker, AverageT_per_Marker, Surface_Areas, ConjugateVar.

I propose to correct this in the spirit of #1225, using containers (std::vector) instead of pointers. There is a bit of additional cleanup.

Related Work

#1225

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • [X ] I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with the '-Wall -Wextra -Wno-unused-parameter -Wno-empty-body' compiler flags, or simply --warnlevel=2 when using meson).
  • My contribution is commented and consistent with SU2 style.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp) , if necessary.

}

SU2_MPI::Allreduce(Local_Surface_Areas, Surface_Areas, config->GetnMarker_HeatFlux(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
SU2_MPI::Allreduce(Local_Surface_Areas, Surface_Areas.data(), config->GetnMarker_HeatFlux(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be problematic (MPI + containers)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not that I am aware of :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no problem, memory is memory, but when doing this I prefer to use the .size() of the container for the MPI count rather than reading it from config or somewhere else.

*Primitive, *Primitive_Flow_i, *Primitive_Flow_j,
*Surface_Areas, Total_HeatFlux_Areas, Total_HeatFlux_Areas_Monitor;
su2double ***ConjugateVar, ***InterfaceVar;
vector<vector<su2double> > HeatFlux;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe someone could add /*!< \brief comments */.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes I can do that, I already worked on the output of the heatsolver ... but I put that on the long bench. I am not sure if all those containers are necessary.
I'll add a commit tomorrow 👍

@maxaehle maxaehle changed the title Fix memoryleaks cheatsolver Fix memory leaks in CHeatSolver Apr 7, 2021
@lgtm-com
Copy link

lgtm-com bot commented Apr 7, 2021

This pull request fixes 6 alerts when merging 84e0585 into e823be7 - view on LGTM.com

fixed alerts:

  • 6 for Resource not released in destructor

Copy link
Contributor

@TobiKattmann TobiKattmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @maxaehle 💐 lgtm

}

SU2_MPI::Allreduce(Local_Surface_Areas, Surface_Areas, config->GetnMarker_HeatFlux(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
SU2_MPI::Allreduce(Local_Surface_Areas, Surface_Areas.data(), config->GetnMarker_HeatFlux(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not that I am aware of :)

*Primitive, *Primitive_Flow_i, *Primitive_Flow_j,
*Surface_Areas, Total_HeatFlux_Areas, Total_HeatFlux_Areas_Monitor;
su2double ***ConjugateVar, ***InterfaceVar;
vector<vector<su2double> > HeatFlux;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes I can do that, I already worked on the output of the heatsolver ... but I put that on the long bench. I am not sure if all those containers are necessary.
I'll add a commit tomorrow 👍

@lgtm-com
Copy link

lgtm-com bot commented Apr 7, 2021

This pull request fixes 6 alerts when merging dad20d7 into 1f7f6bb - view on LGTM.com

fixed alerts:

  • 6 for Resource not released in destructor

@lgtm-com
Copy link

lgtm-com bot commented Apr 8, 2021

This pull request fixes 6 alerts when merging e1896e6 into 1f7f6bb - view on LGTM.com

fixed alerts:

  • 6 for Resource not released in destructor

Comment on lines +234 to +235
auto M = N.size();
AllocVectorOfVectors(M, N, X, val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea with the overload 👍

@pr-triage pr-triage bot removed the PR: unreviewed label Apr 8, 2021
X.resize(M);
for(size_t i = 0; i < M; ++i){
X[i].resize(N[i]);
for (auto& x : X[i]) x = val;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it a bit to try to make it compatible with more types. If I broke anything I'll fix it.
Thanks for all the cleanup.

@lgtm-com
Copy link

lgtm-com bot commented Apr 8, 2021

This pull request fixes 6 alerts when merging 026fbff into 1f7f6bb - view on LGTM.com

fixed alerts:

  • 6 for Resource not released in destructor

@lgtm-com
Copy link

lgtm-com bot commented Apr 14, 2021

This pull request fixes 6 alerts when merging 0e250e1 into 7fa0763 - view on LGTM.com

fixed alerts:

  • 6 for Resource not released in destructor

@maxaehle maxaehle merged commit 13c9943 into develop Apr 14, 2021
@maxaehle maxaehle deleted the fix_memoryleaks_cheatsolver branch April 14, 2021 15:14
@TobiKattmann TobiKattmann mentioned this pull request May 8, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants