From 6b6a113dd688cb470a892b875c0a4150860855af Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 12 Oct 2024 02:14:09 +0000 Subject: [PATCH] Make destructors safe to call with nil receivers --- coordseq.go | 3 +++ geometry/geometry.go | 3 +++ prepgeom.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/coordseq.go b/coordseq.go index 9fd620a73..3b61393a5 100644 --- a/coordseq.go +++ b/coordseq.go @@ -21,6 +21,9 @@ func (s *CoordSeq) Clone() *CoordSeq { // Destroy destroys s and all resources associated with s. func (s *CoordSeq) Destroy() { + if s == nil || s.context == nil { + return + } s.context.Lock() defer s.context.Unlock() C.GEOSCoordSeq_destroy_r(s.context.handle, s.s) diff --git a/geometry/geometry.go b/geometry/geometry.go index 20f0b2f2c..0bd1da9c3 100644 --- a/geometry/geometry.go +++ b/geometry/geometry.go @@ -31,6 +31,9 @@ func (g *Geometry) Bounds() *geos.Box2D { // Destroy destroys g's geom. func (g *Geometry) Destroy() { + if g == nil || g.Geom == nil { + return + } g.Geom.Destroy() g.Geom = nil } diff --git a/prepgeom.go b/prepgeom.go index 5e0860ba5..48037f920 100644 --- a/prepgeom.go +++ b/prepgeom.go @@ -129,6 +129,9 @@ func (pg *PrepGeom) Crosses(g *Geom) bool { // Destroy destroys pg and all resources associated with s. func (pg *PrepGeom) Destroy() { + if pg == nil || pg.parent == nil || pg.parent.context == nil { + return + } pg.parent.context.Lock() defer pg.parent.context.Unlock() C.GEOSPreparedGeom_destroy_r(pg.parent.context.handle, pg.pgeom)