ShmAllocator allocated buffer lifecycle management

Hi all

I’m trying to create a custom rust sink which sinks ShmAllocator allocated buffers into a unix domain socket. It works by sending the file descriptor associated with the buffer’s memory, together with some JSON message containing buffer metadata, over the socket to the consumer.

Pseudo:

let fd = mem
    .downcast_memory_ref::<gst_allocators::FdMemory>()
    .map(|mem| mem.fd())

stream.send_fds(command.serialize()?.as_bytes(), &[fd])

What is unclear to me however is what mechanism I should use to prevent the ShmAllocator from reusing this memory again? Should I just keep a reference to the buffer in the element’s state and drop it when I get a “DONE” answer from the consumer over the socket?

Thanks in advance for any insights and/or pointers!

Robbert