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 all 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
9 changes: 7 additions & 2 deletions src/fields_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,17 @@ void fields::load_fields_chunk_field(h5file *h5f, bool single_parallel_file,
size_t n = num_f[(chunk_i * NUM_FIELD_COMPONENTS + c) * 2 + d];
realnum **f = field_ptr_getter(chunks[i], c, d);
if (n == 0) {
delete[] * f;
delete[] *f;
*f = NULL;
} else {
if (n != ntot)
meep::abort("grid size mismatch %zd vs %zd in fields::load", n, ntot);
*f = new realnum[ntot];
// here we need to allocate the fields array for H in the PML region
// because of H = B in fields_chunk::alloc_f whereby H is lazily
// allocated in fields_chunk::update_eh during the first timestep
const direction d_c = component_direction(c);
if (!(*f) || (*f && is_magnetic(component(c)) && chunks[i]->s->sigsize[d_c] > 1))
*f = new realnum[ntot];
my_ntot += ntot;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/structure_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ 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);
chunks[i]->chi1inv[c][d] = new realnum[ntot];
if (!chunks[i]->chi1inv[c][d]) chunks[i]->chi1inv[c][d] = new realnum[ntot];
stevengj marked this conversation as resolved.
Show resolved Hide resolved
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