0xPolygonID/c-polygonid

Memory allocated in Golang by C.CString() should be freed

Closed this issue · 1 comments

*jsonResponse = C.CString(string(respB))

A function should be provided to be called by flutter/dart, to release the memory allocated by C.CString()

//PLGNFreeCString frees the memory allocated by Golang(using C.CString() ) for the given C string.
//It ensures a consistent and controlled memory management within Go code.
//export PLGNFreeCString 
func PLGNFreeCString(str *C.char) {
	// Note: We do not perform a null check here as C's free function can handle null safely.
    C.free(unsafe.Pointer(str))
}

Like func PLGNFreeStatus(status *C.PLGNStatus) here:

//export PLGNFreeStatus
func PLGNFreeStatus(status *C.PLGNStatus) {
_, cancel := logAPITime()
defer cancel()
if status == nil {
return
}
if status.error_msg != nil {
C.free(unsafe.Pointer(status.error_msg))
}
C.free(unsafe.Pointer(status))
}