Qt: Fix memory leaks in SVG helpers

This commit is contained in:
Stenzek
2026-06-14 16:48:02 +10:00
parent 2c527f4f2c
commit 7d19968270
2 changed files with 14 additions and 3 deletions
+12 -1
View File
@@ -130,6 +130,9 @@ SVGIconEngine::~SVGIconEngine()
bool SVGIconEngine::ensureLoaded() const
{
if (m_document)
return true;
// Previous load failed?
if (m_resource_path.isEmpty())
return false;
@@ -171,7 +174,7 @@ QPixmap SVGIconEngine::getPixmap(const QSize& size, qreal dpr, QIcon::Mode mode,
if (!QPixmapCache::find(cache_key, &pm))
{
// Don't reload multiple times if we hit the cache.
if (ensureLoaded() && RenderSVGToPixmap(pm, m_document, scaled_size, color))
if ((m_document || ensureLoaded()) && RenderSVGToPixmap(pm, m_document, scaled_size, color))
{
if (!m_is_colored && mode != QIcon::Normal)
{
@@ -241,6 +244,14 @@ QIconEngine* SVGIconEnginePlugin::create(const QString& resource_path)
return nullptr;
}
SVGImageHandler::SVGImageHandler() = default;
SVGImageHandler::~SVGImageHandler()
{
if (m_document)
plutosvg_document_destroy(m_document);
}
bool SVGImageHandler::canRead() const
{
if (m_document)
+2 -2
View File
@@ -76,8 +76,8 @@ public:
class SVGImageHandler final : public QImageIOHandler
{
public:
SVGImageHandler() = default;
~SVGImageHandler() override = default;
SVGImageHandler();
~SVGImageHandler() override;
/// Lazily load and parse the SVG data from device(). Returns false on failure.
bool canRead() const override;