Skip to content

Commit

Permalink
Correct test in empty() (#969)
Browse files Browse the repository at this point in the history
Resolves #745
  • Loading branch information
sgillies authored Aug 18, 2020
1 parent e214bc0 commit 726f8cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes
1.7.1 (TBD)
-----------

- Correct the test in ``shapely.geometry.base.BaseGeometry.empty()`` to
eliminate memory leaks like the one reported in #745.
- Get free() not from libc but from the processes global symbols (#891),
fixing a bug that manifests on OS X 10.15 and 10.16.
- Extracting substrings from complex lines has been made more correct (#848,
Expand Down
10 changes: 6 additions & 4 deletions shapely/geometry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from binascii import a2b_hex
from ctypes import pointer, c_size_t, c_char_p, c_void_p
from itertools import islice
import logging
import math
import sys
from warnings import warn
Expand All @@ -21,6 +22,7 @@
from shapely.geos import lgeos
from shapely.impl import DefaultImplementation, delegated

log = logging.getLogger(__name__)

if sys.version_info[0] < 3:
range = xrange
Expand Down Expand Up @@ -220,13 +222,13 @@ class BaseGeometry(object):
_lgeos = lgeos

def empty(self, val=EMPTY):
# TODO: defer cleanup to the implementation. We shouldn't be
# explicitly calling a lgeos method here.
if not self._is_empty and not self._other_owned and self.__geom__:
if not self._other_owned and self.__geom__ and self.__geom__ != EMPTY:
try:
self._lgeos.GEOSGeom_destroy(self.__geom__)
except (AttributeError, TypeError):
pass # _lgeos might be empty on shutdown
# _lgeos might be empty on shutdown
log.exception("Failed to delete GEOS geom")

self._is_empty = True
self.__geom__ = val

Expand Down

0 comments on commit 726f8cf

Please sign in to comment.