Skip to content

Commit

Permalink
Fix memory leaks (#1839)
Browse files Browse the repository at this point in the history
* Fix memory leaks

* Add kkg to authors list
  • Loading branch information
kkg4theweb authored Dec 2, 2021
1 parent f9bd757 commit 087d92c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Robin Dunn <robin@alldunn.com>
Ian Williamson <iwill@google.com>
Andreas Hoenselaar <ahoens@google.com>
Ben Bartlett <benbartlett@stanford.edu>
Krishna Gadepalli <kkg4theweb@gmail.com>
9 changes: 5 additions & 4 deletions src/GDSIIgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ geometric_object_list get_GDSII_prisms(material_type material, const char *GDSII
for (int np = 0; np < num_prisms; np++) {
dVec polygon = polygons[np];
int num_vertices = polygon.size() / 2;
vector3 *vertices = new vector3[num_vertices];
auto vertices = std::make_unique<vector3[]>(num_vertices);
for (int nv = 0; nv < num_vertices; nv++) {
vertices[nv].x = polygon[2 * nv + 0];
vertices[nv].y = polygon[2 * nv + 1];
vertices[nv].z = zmin;
}
double height = zmax - zmin;
vector3 zaxis = {0, 0, 1};
prisms.items[np] = make_prism(material, vertices, num_vertices, height, zaxis);
prisms.items[np] =
make_prism(material, vertices.get(), num_vertices, height, zaxis);
}
return prisms;
}
Expand All @@ -169,7 +170,7 @@ geometric_object get_GDSII_prism(material_type material, const char *GDSIIFile,
dVec polygon = get_polygon(GDSIIFile, Text, Layer);

int num_vertices = polygon.size() / 2;
vector3 *vertices = new vector3[num_vertices];
auto vertices = std::make_unique<vector3[]>(num_vertices);
for (int nv = 0; nv < num_vertices; nv++) {
vertices[nv].x = polygon[2 * nv + 0];
vertices[nv].y = polygon[2 * nv + 1];
Expand All @@ -178,7 +179,7 @@ geometric_object get_GDSII_prism(material_type material, const char *GDSIIFile,

double height = zmax - zmin;
vector3 zaxis = {0, 0, 1};
return make_prism(material, vertices, num_vertices, height, zaxis);
return make_prism(material, vertices.get(), num_vertices, height, zaxis);
}

geometric_object get_GDSII_prism(material_type material, const char *GDSIIFile, int Layer,
Expand Down
3 changes: 2 additions & 1 deletion src/meepgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ geom_epsilon::geom_epsilon(const geom_epsilon &geps1) {
geom_epsilon::~geom_epsilon() {
int length = geometry.num_items;
for (int i = 0; i < length; i++){
delete geometry.items[i].material;
material_free((material_type)geometry.items[i].material);
geometric_object_destroy(geometry.items[i]);
}
delete[] geometry.items;
unset_volume();
Expand Down

0 comments on commit 087d92c

Please sign in to comment.