Skip to content

Commit

Permalink
Fix memory leak when using small caps font
Browse files Browse the repository at this point in the history
The small caps version of a font is kept as a QFontPrivate*
which is manually reference counted, but we neglected to
actually delete it when the reference count went to 0.

[ChangeLog][Fonts] Fixed a memory leak when initializing
a small caps font.

Fixes: QTBUG-93068
Pick-to: 6.1 5.15
Change-Id: Icc7fb7a59bf523da84d2e6fa026940a7d1230525
Reviewed-by: Konstantin Ritt <[email protected]>
Reviewed-by: Robert Löhning <[email protected]>
  • Loading branch information
eskilblomfeldt committed May 20, 2021
1 parent ea3a4a5 commit 11a40de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/gui/text/qfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ QFontPrivate::~QFontPrivate()
if (engineData && !engineData->ref.deref())
delete engineData;
engineData = nullptr;
if (scFont && scFont != this)
scFont->ref.deref();
if (scFont && scFont != this) {
if (!scFont->ref.deref())
delete scFont;
}
scFont = nullptr;
}

Expand Down Expand Up @@ -650,8 +652,10 @@ void QFont::detach()
if (d->engineData && !d->engineData->ref.deref())
delete d->engineData;
d->engineData = nullptr;
if (d->scFont && d->scFont != d.data())
d->scFont->ref.deref();
if (d->scFont && d->scFont != d.data()) {
if (!d->scFont->ref.deref())
delete d->scFont;
}
d->scFont = nullptr;
return;
}
Expand Down

0 comments on commit 11a40de

Please sign in to comment.