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 SWIG wrappers. #1826

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ void _get_gradient(PyObject *grad, PyObject *fields_a, PyObject *fields_f, PyObj
if ($1.num_items != 0) {
for (int i = 0; i < $1.num_items; i++) {
material_free($1.items[i]);
delete $1.items[i];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it would be better to put this in material_free?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could - but then it might break the code of anybody using the C++ api directly.
I dont know how much we worry about that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not so worried about that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I pushed a patch to move delete into material_free. It looks like there was another memory leak in set_default_material that this fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for making the change. I tested this internally and everything looks good.
Please go ahead and merge this change.

}
}
delete[] $1.items;
Expand Down Expand Up @@ -1511,6 +1512,7 @@ void _get_gradient(PyObject *grad, PyObject *fields_a, PyObject *fields_f, PyObj
// it gets garbage collected and the file gets closed.
%newobject meep::fields::open_h5file;

%newobject meep::make_output_directory;
%newobject _get_eigenmode;

%rename(_vec) meep::vec::vec;
Expand Down