formatutils: ensure we dont leak name ptr (#2)

store format name in a std::string and free the char ptr to ensure we
dont leak on each call to drmGetFormatName.
This commit is contained in:
Tom Englund 2024-07-05 15:18:44 +02:00 committed by GitHub
parent c5cf93a3cc
commit 2a3ff6a61d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,8 @@
#include <xf86drm.h>
std::string fourccToName(uint32_t drmFormat) {
auto fmt = drmGetFormatName(drmFormat);
return fmt ? fmt : "unknown";
auto fmt = drmGetFormatName(drmFormat);
std::string name = fmt ? fmt : "unknown";
free(fmt);
return name;
}