diff --git a/cpp/winrtutils/winrtsnapshot.cpp b/cpp/winrtutils/winrtsnapshot.cpp index 98aa9759..ffcd5134 100644 --- a/cpp/winrtutils/winrtsnapshot.cpp +++ b/cpp/winrtutils/winrtsnapshot.cpp @@ -29,30 +29,21 @@ int GetEncoderClsid(const WCHAR *format, CLSID *pClsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes - - Gdiplus::ImageCodecInfo *pImageCodecInfo = NULL; - Gdiplus::GetImageEncodersSize(&num, &size); if (size == 0) return -1; // Failure - pImageCodecInfo = (Gdiplus::ImageCodecInfo *)(malloc(size)); - if (pImageCodecInfo == NULL) - return -1; // Failure - - GetImageEncoders(num, size, pImageCodecInfo); + auto pImageCodecInfo = std::make_unique(num); + GetImageEncoders(num, size, pImageCodecInfo.get()); for (UINT j = 0; j < num; ++j) { if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) { *pClsid = pImageCodecInfo[j].Clsid; - free(pImageCodecInfo); return j; // Success } } - - free(pImageCodecInfo); return -1; // Failure } void capture_window(HWND window_handle, void (*cb)(byte *, size_t))