std::unique_ptr
supports a custom deleter. Since you're allocating with malloc
, you can use free
:
std::unique_ptr<Gdiplus::PropertyItem, void (*)(void*)> propertyItem{
(Gdiplus::PropertyItem*) std::malloc(size), &std::free};
If you prefer to avoid passing the deleter, you can create a struct that does the deletion for you:
struct FreeDeleter {
void operator()(void* p) {
std::free(p);
}
};
std::unique_ptr<Gdiplus::PropertyItem, FreeDeleter> propertyItem{
(Gdiplus::PropertyItem*) std::malloc(size)};