Skip to content

Commit

Permalink
Fixed #21662 -- Kept parent reference in prepared geometry
Browse files Browse the repository at this point in the history
Thanks Robert Scott for the report.
  • Loading branch information
claudep committed Dec 24, 2013
1 parent 1716b7c commit 542198c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django/contrib/gis/geos/prepared.py
Expand Up @@ -12,6 +12,10 @@ class PreparedGeometry(GEOSBase):
ptr_type = capi.PREPGEOM_PTR

def __init__(self, geom):
# Keeping a reference to the original geometry object to prevent it
# from being garbage collected which could then crash the prepared one
# See #21662
self._base_geom = geom
if not isinstance(geom, GEOSGeometry):
raise TypeError
self.ptr = capi.geos_prepare(geom.ptr)
Expand Down
4 changes: 4 additions & 0 deletions django/contrib/gis/geos/tests/test_geos.py
Expand Up @@ -1046,6 +1046,10 @@ def test_prepared(self):
self.assertEqual(mpoly.intersects(pnt), prep.intersects(pnt))
self.assertEqual(c, prep.covers(pnt))

# Original geometry deletion should not crash the prepared one (#21662)
del mpoly
self.assertTrue(prep.covers(Point(5, 5)))

def test_line_merge(self):
"Testing line merge support"
ref_geoms = (fromstr('LINESTRING(1 1, 1 1, 3 3)'),
Expand Down

0 comments on commit 542198c

Please sign in to comment.