Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python bindings: Segfault when accessing sub-geometry after parent has been destroyed #9920

Open
dbaston opened this issue May 14, 2024 · 2 comments
Assignees

Comments

@dbaston
Copy link
Member

dbaston commented May 14, 2024

What is the bug?

Accessing a sub-geometry after its parent has been destroyed causes a segfault. The sub-geometry should either keep a strong reference on its parent (may lead to unexpected behavior somewhere?) or the parent should invalidate references to its children on destruction.

Steps to reproduce the issue

g = ogr.CreateGeometryFromWkt("Point (0 0)")
q = g.Buffer(1).GetGeometryRef(0)
q.GetPointCount() # segfault

Versions and provenance

master

Additional context

No response

@dbaston dbaston self-assigned this May 14, 2024
@rouault
Copy link
Member

rouault commented May 14, 2024

I don't see a particular issue in trying to keep alive the parent in GetGeometryRef().

Not sure if you're aware of it, but ther are complications regarding life-time of geometries with RemoveGeometry(). But that's a more advanced/rare use case than the one of g.Buffer(1).GetGeometryRef(0), so it could be left aside

>>> from osgeo import ogr
>>> g = ogr.CreateGeometryFromWkt("MultiPoint ((0 0))")
>>> point = g.GetGeometryRef(0)
>>> g.RemoveGeometry(0)
>>> point.ExportToWkt()
Segmentation fault (core dumped)

@dbaston
Copy link
Member Author

dbaston commented May 29, 2024

Related: #4401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants