Qt: Fix memory leaks in SVG helpers

pull/3754/head v0.1-11443
Stenzek 3 months ago
parent 2c527f4f2c
commit 7d19968270
No known key found for this signature in database

@ -130,6 +130,9 @@ SVGIconEngine::~SVGIconEngine()
bool SVGIconEngine::ensureLoaded() const bool SVGIconEngine::ensureLoaded() const
{ {
if (m_document)
return true;
// Previous load failed? // Previous load failed?
if (m_resource_path.isEmpty()) if (m_resource_path.isEmpty())
return false; return false;
@ -171,7 +174,7 @@ QPixmap SVGIconEngine::getPixmap(const QSize& size, qreal dpr, QIcon::Mode mode,
if (!QPixmapCache::find(cache_key, &pm)) if (!QPixmapCache::find(cache_key, &pm))
{ {
// Don't reload multiple times if we hit the cache. // 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) if (!m_is_colored && mode != QIcon::Normal)
{ {
@ -241,6 +244,14 @@ QIconEngine* SVGIconEnginePlugin::create(const QString& resource_path)
return nullptr; return nullptr;
} }
SVGImageHandler::SVGImageHandler() = default;
SVGImageHandler::~SVGImageHandler()
{
if (m_document)
plutosvg_document_destroy(m_document);
}
bool SVGImageHandler::canRead() const bool SVGImageHandler::canRead() const
{ {
if (m_document) if (m_document)

@ -76,8 +76,8 @@ public:
class SVGImageHandler final : public QImageIOHandler class SVGImageHandler final : public QImageIOHandler
{ {
public: public:
SVGImageHandler() = default; SVGImageHandler();
~SVGImageHandler() override = default; ~SVGImageHandler() override;
/// Lazily load and parse the SVG data from device(). Returns false on failure. /// Lazily load and parse the SVG data from device(). Returns false on failure.
bool canRead() const override; bool canRead() const override;

Loading…
Cancel
Save