From dd7c011da9d99471a9727d5acf751b0cc5e3056a Mon Sep 17 00:00:00 2001 From: dsquane Date: Fri, 24 Jul 2020 10:45:54 -0600 Subject: [PATCH 1/4] Fixed memory leak --- geos/geom.go | 2 +- geos/wkt.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/geos/geom.go b/geos/geom.go index 964bcd3..0c85e7c 100644 --- a/geos/geom.go +++ b/geos/geom.go @@ -34,7 +34,7 @@ type Geometry struct { func geomFromPtr(ptr *C.GEOSGeometry) *Geometry { g := &Geometry{g: ptr} runtime.SetFinalizer(g, func(g *Geometry) { - cGEOSGeom_destroy(ptr) + cGEOSGeom_destroy(g.g) }) return g } diff --git a/geos/wkt.go b/geos/wkt.go index cf4a2a6..dad39f1 100644 --- a/geos/wkt.go +++ b/geos/wkt.go @@ -63,6 +63,7 @@ func (e *wktEncoder) encode(g *Geometry) (string, error) { if cstr == nil { return "", Error() } + defer C.free(unsafe.Pointer(cstr)) return C.GoString(cstr), nil } From b7d811afca5ee4745d59cdf30e8347252afeb48b Mon Sep 17 00:00:00 2001 From: dsquane Date: Fri, 24 Jul 2020 13:48:41 -0600 Subject: [PATCH 2/4] Removed old repo references --- geos/example_test.go | 2 +- geos/examples.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geos/example_test.go b/geos/example_test.go index 488df4f..bdce900 100644 --- a/geos/example_test.go +++ b/geos/example_test.go @@ -3,7 +3,7 @@ package geos_test import ( "fmt" - "github.com/paulsmith/gogeos/geos" + "github.com/denverquane/gogeos/geos" ) func ExampleGeometry_LineInterpolatePoint() { diff --git a/geos/examples.go b/geos/examples.go index 593c1d9..04a6d62 100644 --- a/geos/examples.go +++ b/geos/examples.go @@ -13,7 +13,7 @@ import ( "code.google.com/p/draw2d/draw2d" - "github.com/paulsmith/gogeos/geos" + "github.com/denverquane/gogeos/geos" ) const ( From 930df107ea1b98b4882178a9b93de67bc38c6be7 Mon Sep 17 00:00:00 2001 From: dsquane Date: Mon, 27 Jul 2020 11:14:46 -0600 Subject: [PATCH 3/4] Reverted changes from master; only doing PR for memory leak --- geos/example_test.go | 2 +- geos/examples.go | 2 +- geos/geom.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/geos/example_test.go b/geos/example_test.go index bdce900..488df4f 100644 --- a/geos/example_test.go +++ b/geos/example_test.go @@ -3,7 +3,7 @@ package geos_test import ( "fmt" - "github.com/denverquane/gogeos/geos" + "github.com/paulsmith/gogeos/geos" ) func ExampleGeometry_LineInterpolatePoint() { diff --git a/geos/examples.go b/geos/examples.go index 04a6d62..593c1d9 100644 --- a/geos/examples.go +++ b/geos/examples.go @@ -13,7 +13,7 @@ import ( "code.google.com/p/draw2d/draw2d" - "github.com/denverquane/gogeos/geos" + "github.com/paulsmith/gogeos/geos" ) const ( diff --git a/geos/geom.go b/geos/geom.go index 0c85e7c..964bcd3 100644 --- a/geos/geom.go +++ b/geos/geom.go @@ -34,7 +34,7 @@ type Geometry struct { func geomFromPtr(ptr *C.GEOSGeometry) *Geometry { g := &Geometry{g: ptr} runtime.SetFinalizer(g, func(g *Geometry) { - cGEOSGeom_destroy(g.g) + cGEOSGeom_destroy(ptr) }) return g } From a2f51e28becf5edafe7db3b93e1cf33ddf310f52 Mon Sep 17 00:00:00 2001 From: dsquane Date: Mon, 27 Jul 2020 17:26:23 -0600 Subject: [PATCH 4/4] Added keepalives in attempt to alleviate segfault --- geos/wkt.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/geos/wkt.go b/geos/wkt.go index dad39f1..6bf85b5 100644 --- a/geos/wkt.go +++ b/geos/wkt.go @@ -31,6 +31,7 @@ func (d *wktDecoder) decode(wkt string) (*Geometry, error) { cstr := C.CString(wkt) defer C.free(unsafe.Pointer(cstr)) g := cGEOSWKTReader_read(d.r, cstr) + runtime.KeepAlive(d) if g == nil { return nil, Error() } @@ -60,6 +61,7 @@ func newWktEncoder() *wktEncoder { // Encode returns a string that is the geometry encoded as WKT func (e *wktEncoder) encode(g *Geometry) (string, error) { cstr := cGEOSWKTWriter_write(e.w, g.g) + runtime.KeepAlive(e) if cstr == nil { return "", Error() }