mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 07:21:32 +08:00
FIX: Address Mac CGO Crash (#3590)
* Copy request to Go memory * Update changelog.mdx * Update v2/pkg/assetserver/webview/responsewriter_darwin.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix import --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
9995dae4ad
commit
3f83b42db5
@ -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)) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user