Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Address Mac CGO Crash #3590

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions v2/pkg/assetserver/webview/responsewriter_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import "C"

import (
"encoding/json"
"fmt"
"net/http"
"unsafe"
)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading