bohoomil / fontconfig-ultimate

freetype2-infinality run-time settings => infinality compatible fontconfig => infinality-bundle
454 stars 38 forks source link

Memory leak in kde 4 plasma when libfreetype infinality is installed #112

Open vdcow opened 8 years ago

vdcow commented 8 years ago

On of the Alt Linux users reported memory leak in KDE 4 plasma when libfreetype-infinality installed. After small amount of time plasma eats about 2 GBs of memory and crashes with follow backtrace:

[KCrash Handler]
#6  _lcd_stem_align (bitmap=bitmap@entry=0x827c23c, mode=mode@entry=FT_RENDER_MODE_LCD, slot=slot@entry=0x827c1f0, translate_value=0xbffdfb9c, scale_value=0xbffdfba0, alignment_strength=100, fitting_strength=100, embolden_value=0xbffdfbe0) at /usr/src/debug/libfreetype-infinality-2.6.0/src/smooth/ftsmooth.c:1960
#7  0xb1bda3e8 in ft_smooth_render_generic (render=render@entry=0x8345ce0, slot=slot@entry=0x827c1f0, mode=mode@entry=FT_RENDER_MODE_LCD, origin=0x0, required_mode=FT_RENDER_MODE_LCD) at /usr/src/debug/libfreetype-infinality-2.6.0/src/smooth/ftsmooth.c:3870
#8  0xb1bdbe5d in ft_smooth_render_lcd (render=0x8345ce0, slot=0x827c1f0, mode=FT_RENDER_MODE_LCD, origin=0x0) at /usr/src/debug/libfreetype-infinality-2.6.0/src/smooth/ftsmooth.c:4127
#9  0xb1b86466 in FT_Render_Glyph_Internal (library=0x832dd48, slot=0x827c1f0, render_mode=FT_RENDER_MODE_LCD) at /usr/src/debug/libfreetype-infinality-2.6.0/src/base/ftobjs.c:4178
#10 0xb1b864e6 in FT_Render_Glyph (slot=0x827c1f0, render_mode=FT_RENDER_MODE_LCD) at /usr/src/debug/libfreetype-infinality-2.6.0/src/base/ftobjs.c:4257
#11 0xb563cbcb in QFontEngineFT::loadGlyph (this=0x8276300, set=0x8276394, glyph=58, subPixelPosition=..., format=QFontEngine::Format_A32, fetchMetricsOnly=true) at text/qfontengine_ft.cpp:903
#12 0xb563d8d0 in loadGlyph (fetchMetricsOnly=true, format=QFontEngine::Format_None, subPixelPosition=..., glyph=<optimized out>, this=0x8276300) at text/qfontengine_ft_p.h:281
#13 QFontEngineFT::recalcAdvances (this=0x8276300, glyphs=0xbffe0280, flags=...) at text/qfontengine_ft.cpp:1613
#14 0xb557cb58 in hb_getAdvances (font=0x827633c, glyphs=0x4a140, numGlyphs=17, advances=0x4a1c0, flags=0) at text/qfontengine.cpp:105
#15 0xb5decf7a in HB_OpenTypePosition (item=0xbffe04a0, availableGlyphs=17, doLogClusters=1 '\001') at ../3rdparty/harfbuzz/src/harfbuzz-shaper.cpp:1339
#16 0xb5ded1b7 in HB_BasicShape (shaper_item=0xbffe04a0) at ../3rdparty/harfbuzz/src/harfbuzz-shaper.cpp:620
#17 0xb5df1cdf in HB_ShapeItem (shaper_item=0xbffe04a0) at ../3rdparty/harfbuzz/src/harfbuzz-shaper.cpp:1419
#18 0xb5df1f18 in qShapeItem (item=0xbffe04a0) at tools/qharfbuzz.cpp:120
#19 0xb55aaacc in QTextEngine::shapeTextWithHarfbuzz (this=0x5cbb7e10, item=0) at text/qtextengine.cpp:1342

After some investigation I have found that issue was already reported previously but in kde bugzilla

https://bugs.kde.org/show_bug.cgi?id=343737

bohoomil commented 8 years ago

Which version of stock freetype2 is supposed to be used on your of Alt Linux installation?

vdcow commented 8 years ago

@bohoomil 2.6.0

bohoomil commented 8 years ago

Did you compile the library with the upstream patches I've been providing? If yes, consider building the new stock version, 2.6.1, with the Infinality patchset. Now that the freetype2 code base is stable and officially released, there may have been various little bugs and issues fixed that were still present in your version. As this is a minor upgrade, there should be no compatibility issues with the rest of your system. You'll find the updated Infinality patchset in this repo.

(BTW, no Arch user has reported issues with Infinality and Plasma, hence my assumption that the problem can be caused by one of the partial updates I created from upstream's patches.)

vdcow commented 8 years ago

I have built 2.6.1 infinality package. Will ask user to test it.

bohoomil commented 8 years ago

Thanks for the info. Please, report back if this helped.

vdcow commented 8 years ago

User upgraded to 2.6.1 and he is still has memory leak issue.

bohoomil commented 8 years ago

Thank you. Just a couple of questions: is he the only one experiencing the problem? Has anyone else using a similar configuration (Alt Linux + Plasma + freetype2-infinality) reported issues like his? Is his fontconfig-infinality{-ultimate} configuration correct? freetype2 and fontconfig work together and sometimes when the latter is misconfigured the rendering lib may crash. For best results, I'd perform a clean installation of fontconfig-iu, including the removal of all files from both /etc/fonts and $XDG_CONFIG_HOME/fontconfig (back up them first, of course). The location of globally installed fontconfig templates may differ depending on the distribution.

vdcow commented 8 years ago

is he the only one experiencing the problem?

I don't have problem on my machines. But in first post I provided link to the report in kde bugtracker - the same issue was reported by Fedora user in February (for freetype 2.5.0).

Is his fontconfig-infinality{-ultimate} configuration correct?

I am packing original version of fontconfig-infinality with very small modifications (e.g. default font aliases). There is my repo http://git.altlinux.org/people/cow/packages/?p=fontconfig-infinality.git;a=summary

fontconfig work together and sometimes when the latter is misconfigured the rendering lib may crash.

It shouldn't. If lib is crashed because configs are wrong then lib is definitely should be fixed.

bohoomil commented 8 years ago

OK then. We're simply going to leave the issue open: maybe @goddesse will kindly look into it and suggest a solution.

goddesse commented 8 years ago

The segfault is probably because the code assumes the mallocs/reallocs will always succeed. Checking for nullity would fix the crash, but you'd still have an unusable system from the runaway memory. I could set a maximum reasonable memory size that the stem detection can work in and see if that fixes the latter. I'd be curious to know more about the user's system to better understand what's causing the pathological behavior in the first place. @vladimir-didenko could you possibly direct the user here?

In the meantime, the user can avoid these codepaths by turning off stem alignment in infinality_settings.sh by setting both the stem alignment and stem fitting strengths to zero and hopefully that will ameliorate the crashing until I can fix it.

vdcow commented 8 years ago

@goddesse

could you possibly direct the user here?

He has problem with English but he is agree to communicate through me. So describe information you need and I will redirect request to user.

goddesse commented 8 years ago

@vladimir-didenko I would like to know the total amount of system memory, platform endianness, and plasma's UI font and locale. Also, what Alt Linux ISO would get me closest to his environment? 7.0 kdesktop or sisyphus kde4?

vdcow commented 8 years ago

There is user system information:

Also, what Alt Linux ISO would get me closest to his environment?

You can use follow image

http://nightly.altlinux.org/sisyphus/current/regular-kde4-latest-i586.iso

But by default there is no infinality installed. You can install it using follow commands:

su -
apt-get update
apt-get install libfreetype-infinality fontconfig-infinality

Note: I can't reproduce this issue with this image on my VirtualBox.

goddesse commented 8 years ago

@vladimir-didenko The latest release may have fixed this. Would you mind checking with the user?

vdcow commented 8 years ago

@goddesse Yes, I will build new package and will ask user to reproduce issue.