From 58181619a2cdce3623e0024e2e5e52ef6dd5ed9e Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 15 Jan 2024 22:54:55 +0100 Subject: [PATCH 1/2] Free EWKB writer on context destroy --- context.go | 5 ++++- geom.go | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/context.go b/context.go index 9a65e1f53..256f7a006 100644 --- a/context.go +++ b/context.go @@ -14,7 +14,7 @@ import ( type Context struct { sync.Mutex handle C.GEOSContextHandle_t - ewkbWriter *C.struct_GEOSWKBWriter_t + ewkbWithSRIDWriter *C.struct_GEOSWKBWriter_t geoJSONReader *C.struct_GEOSGeoJSONReader_t geoJSONWriter *C.struct_GEOSGeoJSONWriter_t wkbReader *C.struct_GEOSWKBReader_t @@ -376,6 +376,9 @@ func (c *Context) cGeomsLocked(geoms []*Geom) (**C.struct_GEOSGeom_t, func()) { func (c *Context) finish() { c.Lock() defer c.Unlock() + if c.ewkbWithSRIDWriter != nil { + C.GEOSWKBWriter_destroy_r(c.handle, c.ewkbWithSRIDWriter) + } if c.geoJSONReader != nil { C.GEOSGeoJSONReader_destroy_r(c.handle, c.geoJSONReader) } diff --git a/geom.go b/geom.go index ad6580edb..dbacb6960 100644 --- a/geom.go +++ b/geom.go @@ -271,13 +271,13 @@ func (g *Geom) ToEWKBWithSRID() []byte { g.mustNotBeDestroyed() g.context.Lock() defer g.context.Unlock() - if g.context.ewkbWriter == nil { - g.context.ewkbWriter = C.GEOSWKBWriter_create_r(g.context.handle) - C.GEOSWKBWriter_setFlavor_r(g.context.handle, g.context.ewkbWriter, C.GEOS_WKB_EXTENDED) - C.GEOSWKBWriter_setIncludeSRID_r(g.context.handle, g.context.ewkbWriter, 1) + if g.context.ewkbWithSRIDWriter == nil { + g.context.ewkbWithSRIDWriter = C.GEOSWKBWriter_create_r(g.context.handle) + C.GEOSWKBWriter_setFlavor_r(g.context.handle, g.context.ewkbWithSRIDWriter, C.GEOS_WKB_EXTENDED) + C.GEOSWKBWriter_setIncludeSRID_r(g.context.handle, g.context.ewkbWithSRIDWriter, 1) } var size C.size_t - ewkbCBuf := C.GEOSWKBWriter_write_r(g.context.handle, g.context.ewkbWriter, g.geom, &size) + ewkbCBuf := C.GEOSWKBWriter_write_r(g.context.handle, g.context.ewkbWithSRIDWriter, g.geom, &size) defer C.GEOSFree_r(g.context.handle, unsafe.Pointer(ewkbCBuf)) return C.GoBytes(unsafe.Pointer(ewkbCBuf), C.int(size)) } From d3edf59f670458b7e01d5b418bbf430ab42fb621 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 15 Jan 2024 23:02:49 +0100 Subject: [PATCH 2/2] Bump golangci-lint version --- .github/workflows/main.yml | 2 +- .golangci.yml | 19 ++++++++++++------- geojson/geojson.go | 2 +- geometry/kml.go | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8d7b98596..a2e8801bb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc with: - version: v1.54.2 + version: v1.55.2 geos-versions: strategy: fail-fast: false diff --git a/.golangci.yml b/.golangci.yml index f9ec66390..b87588c9e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,15 +20,17 @@ linters: - forbidigo - forcetypeassert - gci + - ginkgolinter - gocheckcompilerdirectives - gochecknoinits - - goconst + - gochecksumtype - gocritic - godot - goerr113 - gofmt - gofumpt - goimports + - gomoddirectives - gomodguard - goprintffuncname - gosec @@ -37,10 +39,12 @@ linters: - govet - grouper - importas + - inamedparam - ineffassign - interfacebloat - ireturn - loggercheck + - makezero - mirror - misspell - musttag @@ -50,11 +54,15 @@ linters: - noctx - nolintlint - nosprintfhostport + - perfsprint - prealloc - predeclared - promlinter + - protogetter - reassign + - revive - rowserrcheck + - sloglint - sqlclosecheck - staticcheck - stylecheck @@ -62,6 +70,7 @@ linters: - tagliatelle - tenv - testableexamples + - testifylint - testpackage - thelper - typecheck @@ -71,34 +80,30 @@ linters: - usestdlibvars - wastedassign - whitespace + - zerologlint disable: - cyclop - depguard - dupl - - exhaustivestruct - exhaustruct - funlen - - ginkgolinter - gochecknoglobals - gocognit + - goconst - gocyclo - godox - goheader - gomnd - - gomoddirectives - lll - maintidx - - makezero - nestif - nlreturn - nonamedreturns - paralleltest - - revive - tparallel - varnamelen - wrapcheck - wsl - - zerologlint linters-settings: gci: diff --git a/geojson/geojson.go b/geojson/geojson.go index cc3086ac6..a0407aea8 100644 --- a/geojson/geojson.go +++ b/geojson/geojson.go @@ -66,7 +66,7 @@ func (fc FeatureCollection) MarshalJSON() ([]byte, error) { feature := feature{ ID: f.ID, Type: featureType, - Geometry: &f.Geometry, //nolint:gosec + Geometry: &f.Geometry, Properties: f.Properties, } features = append(features, feature) diff --git a/geometry/kml.go b/geometry/kml.go index ac3fdfc2f..3048d216f 100644 --- a/geometry/kml.go +++ b/geometry/kml.go @@ -21,7 +21,7 @@ var ( ) // MarshalXML implements encoding/xml.Marshaler. -func (g *Geometry) MarshalXML(e *xml.Encoder, start xml.StartElement) error { +func (g *Geometry) MarshalXML(e *xml.Encoder, _ xml.StartElement) error { return kmlEncodeGeom(e, g.Geom) }