From 44c14470e5b28e45c19d6959b114e063cf3f4d83 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 11 Apr 2012 10:12:23 +0200 Subject: Fix memory leak when drawing text in non-common script When the fontEngine() cached was updated for new parameters, we would overwrite the cached engine, but not deref the old cached engine, thus it would never be deleted. Change-Id: I3b88698712e468ffa634bd98019a7871662cc363 Reviewed-by: Jiang Jiang --- src/gui/text/qtextengine.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 3137de6..8fc3176 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1907,12 +1907,17 @@ QFontEngine *QTextEngine::fontEngine(const QScriptItem &si, QFixed *ascent, QFix font.setPixelSize((font.pixelSize() * 2) / 3); scaledEngine = font.d->engineForScript(script); } - feCache.prevFontEngine = engine; if (engine) engine->ref.ref(); - feCache.prevScaledFontEngine = scaledEngine; + if (feCache.prevFontEngine) + releaseCachedFontEngine(feCache.prevFontEngine); + feCache.prevFontEngine = engine; + if (scaledEngine) scaledEngine->ref.ref(); + if (feCache.prevScaledFontEngine) + releaseCachedFontEngine(feCache.prevScaledFontEngine); + feCache.prevScaledFontEngine = scaledEngine; feCache.prevScript = script; feCache.prevPosition = si.position; feCache.prevLength = length(&si); @@ -1922,9 +1927,11 @@ QFontEngine *QTextEngine::fontEngine(const QScriptItem &si, QFixed *ascent, QFix engine = feCache.prevFontEngine; else { engine = font.d->engineForScript(script); - feCache.prevFontEngine = engine; if (engine) engine->ref.ref(); + if (feCache.prevFontEngine) + releaseCachedFontEngine(feCache.prevFontEngine); + feCache.prevFontEngine = engine; feCache.prevScript = script; feCache.prevPosition = -1; feCache.prevLength = -1; -- cgit v0.12