From 01b793bb55c818e11ed990c666836b5d36b10bec Mon Sep 17 00:00:00 2001 From: Samuel Kogler Date: Fri, 11 Nov 2022 13:08:57 +0100 Subject: [PATCH] Fix memory leak in CRS.to_authority/CRS.list_authority List elements were not properly disposed of when iterating the results of proj_identify. This fixes this and simplifies the cleanup logic. --- docs/history.rst | 1 + pyproj/_crs.pyx | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index 00c6c7c69..c90485e07 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -8,6 +8,7 @@ Latest ----- - BUG: Changed so that the setup.cfg depends on the version code in the __init__.py instead of the other way around (issuue #1155) - BUG: Fix :meth:`.CRS.to_cf` for Pole rotation GRIB convention (pull #1167) +- BUG: Fix :meth:`.CRS.to_authority` memory leak (pull #1178) - REF: Use upper case EPSG code when creating CRS (pull #1162) 3.4.0 diff --git a/pyproj/_crs.pyx b/pyproj/_crs.pyx index 9a0157b3a..4fa8092cb 100644 --- a/pyproj/_crs.pyx +++ b/pyproj/_crs.pyx @@ -2883,9 +2883,13 @@ cdef class _CRS(Base): out_confidence_list[iii] ) ) + # at this point, the auth name is copied and we can release the proj object + proj_destroy(proj) + proj = NULL finally: - for iii in range(num_proj_objects): - proj_destroy(proj_list_get(self.context, proj_list, iii)) + # If there was an error we have to call proj_destroy + # If there was none, calling it on NULL does nothing + proj_destroy(proj) proj_list_destroy(proj_list) CRSError.clear() return authority_list