Skip to content

Commit

Permalink
fix(go/adbc/pkg): guard against potential crash
Browse files Browse the repository at this point in the history
We think malloc'ing a C struct is one possible way the Go garbage
collector may still be seeing invalid Go pointers.  See apache#1931.
  • Loading branch information
lidavidm committed Jun 25, 2024
1 parent c1ad8df commit a09da62
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions go/adbc/pkg/_tmpl/driver.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func setErrWithDetails(err *C.struct_AdbcError, adbcError adbc.Error) {
return
}

cErrPtr := C.malloc(C.sizeof_struct_{{.Prefix}}Error)
cErrPtr := C.calloc(C.sizeof_struct_{{.Prefix}}Error, C.size_t(1))
cErr := (*C.struct_{{.Prefix}}Error)(cErrPtr)
cErr.message = C.CString(adbcError.Msg)
err.message = cErr.message
Expand Down Expand Up @@ -209,7 +209,7 @@ func printLoggingHelp() {
// handle.
func createHandle(hndl cgo.Handle) unsafe.Pointer {
// uintptr_t* hptr = malloc(sizeof(uintptr_t));
hptr := (*C.uintptr_t)(C.malloc(C.sizeof_uintptr_t))
hptr := (*C.uintptr_t)(C.calloc(C.sizeof_uintptr_t, C.size_t(1)))
// *hptr = (uintptr)hndl;
*hptr = C.uintptr_t(uintptr(hndl))
return unsafe.Pointer(hptr)
Expand Down
4 changes: 2 additions & 2 deletions go/adbc/pkg/flightsql/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/adbc/pkg/flightsql/utils.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go/adbc/pkg/panicdummy/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/adbc/pkg/panicdummy/utils.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go/adbc/pkg/snowflake/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/adbc/pkg/snowflake/utils.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a09da62

Please sign in to comment.