pixelherodev commented on code in PR #578:
URL: https://github.com/apache/arrow-go/pull/578#discussion_r2558378255


##########
arrow/ipc/message.go:
##########
@@ -85,7 +84,9 @@ func NewMessage(meta, body *memory.Buffer) *Message {
                meta: meta,
                body: body,
        }
-       m.refCount.Add(1)
+       m.ReferenceBuffer(&m.meta, &m.body)
+       m.ReferenceDerived(unsafe.Pointer(&m.msg))

Review Comment:
   The msg pointer is _derived_ from the `meta` Buffer, which is itself 
allocated by the `Allocator`. `ReferenceDerived` is not for refcounting; it 
basically means "when this object goes free, nil out the target to prevent 
use-after-free."
   
   Without it, accessing the message after calling Release could potentially 
access other memory allocated by the `Allocator` - if integrating with C, this 
could _theoretically_ allow access to other heap allocations. Note that the 
previous code for Message.Release contains this:
   
   ```go
   if msg.refCount.Add(-1) == 0 {
                msg.meta.Release()
                msg.body.Release()
                msg.msg = nil
                msg.meta = nil
                msg.body = nil
        }
   ```
   
   it's releasing the two subresources, but also nilling the one that depends 
on one. This is just to replace the `msg = nil` line, basically.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to