diff --git a/geos/wkt.go b/geos/wkt.go index cf4a2a6..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,9 +61,11 @@ 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() } + defer C.free(unsafe.Pointer(cstr)) return C.GoString(cstr), nil }