FcFini() sends SIGABRT when using Xft
When using Xft and fontconfig, calling FcFini()
after creating XftFont
s with XftFontOpen*()
causes SIGABRT
to be thrown and jamming the program, even after all created XftFont
s have been closed with XftFontClose()
.
Example code:
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include <fontconfig/fontconfig.h>
int main() {
FcInit();
Display *dis = XOpenDisplay(NULL);
int screen = DefaultScreen(dis);
XftFont *f = XftFontOpenName(dis, screen, "sans-serif");
XftFontClose(dis, f);
FcFini();
}
Compile with:
gcc main.c -lfontconfig -lfreetype -lX11 -lXft
And executing it outputs:
$ ./a.out
a.out: fccache.c:525: FcCacheFini: Assertion `fcCacheChains[i] == NULL' failed.
Aborted (core dumped)
And valgrind reports:
==11600== 128 bytes in 1 blocks are definitely lost in loss record 111 of 158
==11600== at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==11600== by 0x4E48493: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x4E441EC: FcConfigSubstituteWithPat (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x566FCA9: XftFontMatch (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566FFD6: XftFontOpenName (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x1088A8: main (in /tmp/test/a.out)
==11600==
==11600== 352 (256 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 127 of 158
==11600== at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==11600== by 0x4E550F9: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x4E55861: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x4E55C1B: FcPatternAddDouble (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x566C4CD: ??? (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566C7C4: ??? (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566CA33: ??? (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566CE8D: XftDefaultHasRender (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566D2B7: XftDefaultSubstitute (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566FCC4: XftFontMatch (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566FFD6: XftFontOpenName (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x1088A8: main (in /tmp/test/a.out)
==11600==
==11600== 2,603 (768 direct, 1,835 indirect) bytes in 1 blocks are definitely lost in loss record 149 of 158
==11600== at 0x4C2DDCF: realloc (vg_replace_malloc.c:785)
==11600== by 0x4E5504A: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x4E55741: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x4E528D8: FcFontRenderPrepare (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x4E52C3F: FcFontMatch (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.8.0)
==11600== by 0x566FCDA: XftFontMatch (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x566FFD6: XftFontOpenName (in /usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
==11600== by 0x1088A8: main (in /tmp/test/a.out)
==11600==
==11600== LEAK SUMMARY:
==11600== definitely lost: 1,152 bytes in 3 blocks
==11600== indirectly lost: 1,931 bytes in 59 blocks
==11600== possibly lost: 0 bytes in 0 blocks
==11600== still reachable: 201,717 bytes in 534 blocks
==11600== suppressed: 0 bytes in 0 blocks
I wonder whether I'm using FcInit()
and FcFini()
right? How does Xft interact with fontconfig? Or is the problem actually one of fontconfig's?