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
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
1 change: 0 additions & 1 deletion libpympb/pympb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,6 @@ void mode_solver::clear_geometry_list() {
if (geometry_list.num_items && geometry_list.items) {
for(int i = 0; i < geometry_list.num_items; ++i) {
material_free((meep_geom::material_data *)geometry_list.items[i].material);
delete (meep_geom::material_data *)geometry_list.items[i].material;
geometric_object_destroy(geometry_list.items[i]);
}
delete[] geometry_list.items;
Expand Down
5 changes: 2 additions & 3 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ meep::volume_list *make_volume_list(const meep::volume &v, int c,
%typemap(freearg) GEOMETRIC_OBJECT {
if ($1.material) {
material_free((material_data *)$1.material);
delete (material_data *)$1.material;
geometric_object_destroy($1);
}
}
Expand Down Expand Up @@ -1001,7 +1000,6 @@ void _get_gradient(PyObject *grad, PyObject *fields_a, PyObject *fields_f, PyObj
%typemap(freearg) material_type {
if ($1) {
material_free($1);
delete $1;
}
}

Expand Down Expand Up @@ -1511,6 +1509,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 Expand Up @@ -2012,7 +2011,7 @@ meep_geom::geom_epsilon* _set_materials(meep::structure * s,
meep_geom::geom_epsilon *existing_geps,
bool output_chunk_costs,
const meep::binary_partition *my_bp) {

meep_geom::geom_epsilon *geps;
if (existing_geps) {
geps = existing_geps;
Expand Down
1 change: 0 additions & 1 deletion python/typemap_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,6 @@ void gobj_list_freearg(geometric_object_list* objs) {
SWIG_PYTHON_THREAD_SCOPED_BLOCK;
for(int i = 0; i < objs->num_items; ++i) {
material_free((material_data *)objs->items[i].material);
delete (material_data *)objs->items[i].material;
geometric_object_destroy(objs->items[i]);
}
delete[] objs->items;
Expand Down
2 changes: 1 addition & 1 deletion src/meepgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ static void set_default_material(material_type _default_material) {
if (default_material != NULL) {
if (default_material == _default_material) return;
material_free((material_type)default_material);
delete (material_type)default_material;
default_material = NULL;
}

Expand Down Expand Up @@ -118,6 +117,7 @@ void material_free(material_type m) {

delete[] m->weights;
m->weights = NULL;
delete m;
}

bool material_type_equal(const material_type m1, const material_type m2) {
Expand Down
1 change: 0 additions & 1 deletion tests/array-slice-ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ int main(int argc, char *argv[]) {
meep_geom::material_type vacuum = meep_geom::vacuum;
auto material_deleter = [](meep_geom::material_data *m) {
meep_geom::material_free(m);
delete m;
};
std::unique_ptr<meep_geom::material_data, decltype(material_deleter)> dielectric(
meep_geom::make_dielectric(eps), material_deleter);
Expand Down