I am using a function (which is part of a library) which returns a raw uint8_t*
pointer to some memory which has been allocated on the heap and holds image pixel data. The caller of this function is responsible for calling free
on the pointer.
My code where I call this function has many branches with early termination and I therefore would need to call free(buffer)
at many points. I think it would be better if I could wrap the buffer in a unique_ptr
so that when it falls out of scope, the memory is automatically freed.
How can I achieve this?
For reference, the function decleration looks something like this: uint8_t* getFrame()
(I already know the width, height, and num channels of the image and thus the length of the buffer);