Skip to content

Commit

Permalink
rados: use ptrguard for writeStep buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Anderson <[email protected]>
  • Loading branch information
ansiwen committed Oct 11, 2021
1 parent 9f711d3 commit e1dfc41
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rados/write_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import "C"

import (
"unsafe"

"github.com/ceph/go-ceph/internal/cutil"
)

type writeStep struct {
withoutUpdate
withoutFree
// the c pointer utilizes the Go byteslice data and no free is needed

// inputs:
b []byte
b []byte
pg *cutil.PtrGuard

// arguments:
cBuffer *C.char
Expand All @@ -23,11 +24,17 @@ type writeStep struct {
}

func newWriteStep(b []byte, writeLen, offset uint64) *writeStep {
bufPtr := unsafe.Pointer(&b[0])
return &writeStep{
b: b,
cBuffer: (*C.char)(unsafe.Pointer(&b[0])),
pg: cutil.NewPtrGuard(bufPtr),
cBuffer: (*C.char)(bufPtr),
cDataLen: C.size_t(len(b)),
cWriteLen: C.size_t(writeLen),
cOffset: C.uint64_t(offset),
}
}

func (v *writeStep) free() {
v.pg.Release()
}

0 comments on commit e1dfc41

Please sign in to comment.