diff --git a/v2/pkg/assetserver/webview/responsewriter_darwin.go b/v2/pkg/assetserver/webview/responsewriter_darwin.go index 77de3c4554f..a3c73b6f117 100644 --- a/v2/pkg/assetserver/webview/responsewriter_darwin.go +++ b/v2/pkg/assetserver/webview/responsewriter_darwin.go @@ -69,6 +69,7 @@ import "C" import ( "encoding/json" + "fmt" "net/http" "unsafe" ) @@ -98,16 +99,31 @@ func (rw *responseWriter) Write(buf []byte) (int, error) { rw.WriteHeader(http.StatusOK) - var content unsafe.Pointer var contentLen int if buf != nil { - content = unsafe.Pointer(&buf[0]) contentLen = len(buf) } - if !C.URLSchemeTaskDidReceiveData(rw.r.task, content, C.int(contentLen)) { - return 0, errRequestStopped + if contentLen > 0 { + // Create a C array to hold the data + cBuf := C.malloc(C.size_t(contentLen)) + if cBuf == nil { + return 0, fmt.Errorf("memory allocation failed for %d bytes", contentLen) + } + defer C.free(cBuf) + + // Copy the Go slice to the C array + C.memcpy(cBuf, unsafe.Pointer(&buf[0]), C.size_t(contentLen)) + + if !C.URLSchemeTaskDidReceiveData(rw.r.task, cBuf, C.int(contentLen)) { + return 0, errRequestStopped + } + } else { + if !C.URLSchemeTaskDidReceiveData(rw.r.task, nil, 0) { + return 0, errRequestStopped + } } + return contentLen, nil } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 368e4103027..72eca05a53c 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed +- Fixed CGO memory issue on Darwin by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3590) - Fixed an error that occurred when an author name contains a string that is not suitable for JSON. Fixed by @taiseiotsuka in [PR](https://github.com/wailsapp/wails/pull/3638) - Fixed MacOS build to use `outputfilename` from wails.json. [#3200](https://github.com/wailsapp/wails/issues/3200) - Fixed file drop events on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/3595) by @FrancescoLuzzi @@ -24,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 + Modified `ZoomFactor` and `IsZoomControlEnabled` options to be Windows-only options in PR[#3644](https://github.com/wailsapp/wails/pull/3644) by @levinit - Added nil check for Drag-n-Drop on Windows. Fixed by in [PR](https://github.com/wailsapp/wails/pull/3597) by @leaanthony based on the suggestion by @Alpa-1 in [#3596](https://github.com/wailsapp/wails/issues/3596). - ## v2.9.1 - 2024-06-18 ### Fixed