Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leaks in structure and fields load during checkpointing #1872

Merged
merged 6 commits into from
Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/fields_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ void fields::load_fields_chunk_field(h5file *h5f, bool single_parallel_file,
} else {
if (n != ntot)
meep::abort("grid size mismatch %zd vs %zd in fields::load", n, ntot);
if (*f) {
delete[] * f;
*f = NULL;
}
stevengj marked this conversation as resolved.
Show resolved Hide resolved
*f = new realnum[ntot];
my_ntot += ntot;
}
Expand Down
4 changes: 4 additions & 0 deletions src/structure_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ void structure::load(const char *filename, bool single_parallel_file) {
}
else {
if (n != ntot) meep::abort("grid size mismatch %zd vs %zd in structure::load", n, ntot);
if (chunks[i]->chi1inv[c][d]) {
delete[] chunks[i]->chi1inv[c][d];
chunks[i]->chi1inv[c][d] = NULL;
}
stevengj marked this conversation as resolved.
Show resolved Hide resolved
chunks[i]->chi1inv[c][d] = new realnum[ntot];
my_ntot += ntot;
}
Expand Down
1 change: 0 additions & 1 deletion tests/dump_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ int test_periodic(double eps(const vec &), int splitting, const char *tmpdir) {
double ttot = 17.0;

grid_volume gv = vol3d(1.5, 0.5, 1.0, a);
structure s1(gv, eps);
structure s(gv, eps, no_pml(), identity(), splitting);

std::string filename_prefix =
Expand Down