Skip to content

Commit

Permalink
Merge pull request #2983 from stichri/cherrypicked-memleakfix
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep authored May 10, 2023
2 parents 6192e4a + e544fc8 commit f77769b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pymatgen/util/coord_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def pbc_shortest_vectors(lattice, fcoords1, fcoords2, mask=None, return_d2=False
pbc = lattice.pbc
cdef int n_pbc = sum(pbc)
cdef int n_pbc_im = 3 ** n_pbc
cdef np.float_t[:, ::1] frac_im = <np.float_t[:n_pbc_im, :3]> malloc(3 * n_pbc_im * sizeof(np.float_t))

cdef np.float_t[:, ::1] frac_im
cdef int i, j, k, l, I, J

if n_pbc == 3:
Expand All @@ -101,6 +101,7 @@ def pbc_shortest_vectors(lattice, fcoords1, fcoords2, mask=None, return_d2=False
matrix = lattice.lll_matrix
frac_im = images_view
else:
frac_im = <np.float_t[:n_pbc_im, :3]> malloc(3 * n_pbc_im * sizeof(np.float_t))
matrix = lattice.matrix.copy()
k = 0
for i in range(27):
Expand Down Expand Up @@ -178,6 +179,8 @@ def pbc_shortest_vectors(lattice, fcoords1, fcoords2, mask=None, return_d2=False
for l in range(3):
vs[i, j, l] = 1e20

if not (n_pbc == 3):
free(&frac_im[0,0])
free(&cart_f1[0,0])
free(&cart_f2[0,0])
free(&cart_im[0,0])
Expand Down

0 comments on commit f77769b

Please sign in to comment.