From 02aee5d174b0a1d0f925dc5c3243f77d0dc0c8c4 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 2 Jul 2012 07:44:27 +0300 Subject: DirectWrite font engine: don't leak the font table buffer Ideally, each TryGetFontTable() call sequence should be followed by the call to ReleaseFontTable() with the context value taken from the first TryGetFontTable() call, otherwise we'll leak the buffer allocated for the font table. Change-Id: I627bf0133b7f61798e82929723ccfb780ce9ee69 Reviewed-by: Friedemann Kleint Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../windows/qwindowsfontenginedirectwrite.cpp | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index b02686ceeb..568de480a0 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -254,6 +254,8 @@ QFixed QWindowsFontEngineDirectWrite::lineThickness() const bool QWindowsFontEngineDirectWrite::getSfntTableData(uint tag, uchar *buffer, uint *length) const { + bool ret = false; + if (m_directWriteFontFace) { DWORD t = qbswap(tag); @@ -266,26 +268,22 @@ bool QWindowsFontEngineDirectWrite::getSfntTableData(uint tag, uchar *buffer, ui ); if (SUCCEEDED(hr)) { - if (!exists) - return false; - - if (buffer == 0) { - *length = tableSize; - return true; - } else if (*length < tableSize) { - return false; + if (exists) { + if (!buffer) { + *length = tableSize; + ret = true; + } else if (*length >= tableSize) { + memcpy(buffer, tableData, tableSize); + ret = true; + } } - - memcpy(buffer, tableData, tableSize); m_directWriteFontFace->ReleaseFontTable(tableContext); - - return true; } else { qErrnoWarning("%s: TryGetFontTable failed", __FUNCTION__); } } - return false; + return ret; } QFixed QWindowsFontEngineDirectWrite::emSquareSize() const -- cgit v1.2.3