You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
Found a bug in encodeWkb() for windows.
A buffer allocated in geos_c.dll whith malloc() cannot simply be freed with C.free(). Must use cGEOSFree().
Now all tests pass.
The modified code follows:
func encodeWkb(e *wkbEncoder, g *Geometry, fn func(*C.GEOSWKBWriter, *C.GEOSGeometry, *C.size_t) *C.uchar) ([]byte, error) {
var size C.size_t
bytes := fn(e.w, g.g, &size)
if bytes == nil {
return nil, Error()
}
ptr := unsafe.Pointer(bytes)
defer cGEOSFree((*C.void)(ptr)) //instead of C.free(ptr)
l := int(size)
var out []byte
for i := 0; i < l; i++ {
el := unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(C.uchar(0))*uintptr(i))
out = append(out, byte(*(*C.uchar)(el)))
}
return out, nil
}
The text was updated successfully, but these errors were encountered:
Hi. Thanks for the solution. It really helped me. Btw, can u explain the reason for that?
Hi. When you allocate memory in dll (win) with malloc you use a specific heap of dll, not a system wide one. So you must free the same memory using the same pointer local to dll code. The way to do this is to call a public entry point that calls free on the ptr of the specific heap from which it was allocated. GEOSFree is such a public method.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Found a bug in encodeWkb() for windows.
A buffer allocated in geos_c.dll whith malloc() cannot simply be freed with C.free(). Must use cGEOSFree().
Now all tests pass.
The modified code follows:
The text was updated successfully, but these errors were encountered: