driverkitmacos-system-extension

Should IOBufferMemoryDescriptor be released of free'd?


I am looking at the documentation of IOBufferMemoryDescriptor. It says "... Except where noted, you are also responsible for releasing buffers that you allocate.".

IOBufferMemoryDescriptor::free also exists. My questions is: should I use free or release (or maybe both) to do the cleanup?


Solution

  • free() is called automatically when the last handle is dropped using OSSafeReleaseNULL. (This calls release() internally, but it's usually best to use the macro.)

    So, never call the free() method directly, you only need to care about it in the context of overriding it in your own subclasses. Always use the reference counting mechanism on OSObject-derived classes.