Re: [dev] [libsl][bug] Call FcFini on cleanup for projects calling FcIni

2022-10-30 Thread NRK
On Sun, Oct 30, 2022 at 12:50:54PM -0700, Anskrevy wrote:
> And here is my valgrind output
> https://gist.github.com/Anskrevy/b981453fb7fbe3fb410ac1dd883d23ad

Looking at the backtrace it doesn't seem like it generated anywhere from
libsl (or your program)

==2726510== 288 (256 direct, 32 indirect) bytes in 1 blocks are 
definitely lost in loss record 192 of 320
==2726510==at 0x4841888: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2726510==by 0x49E9F25: FcPatternObjectInsertElt (fcpat.c:525)
==2726510==by 0x49EE180: FcPatternObjectAddWithBinding (fcpat.c:711)
==2726510==by 0x49FC079: UnknownInlinedFun (fcpat.c:1258)
==2726510==by 0x49FC079: UnknownInlinedFun (fcxml.c:3109)
==2726510==by 0x49FC079: FcEndElement (fcxml.c:3234)
==2726510==by 0x4D2E61E: doContent (xmlparse.c:3047)
==2726510==by 0x4D2BCB3: UnknownInlinedFun (xmlparse.c:2612)
==2726510==by 0x4D2BCB3: doProlog (xmlparse.c:4893)
==2726510==by 0x4D2D7CC: prologProcessor (xmlparse.c:4598)
==2726510==by 0x4D31879: XML_ParseBuffer (xmlparse.c:2009)
==2726510==by 0x49F67E4: 
FcConfigParseAndLoadFromMemoryInternal.lto_priv.0 (fcxml.c:3544)
==2726510==by 0x49F7136: _FcConfigParse.lto_priv.0 (fcxml.c:3679)
==2726510==by 0x49F7319: UnknownInlinedFun (fcxml.c:3447)
==2726510==by 0x49F7319: _FcConfigParse.lto_priv.0 (fcxml.c:3638)
==2726510==by 0x49FA2F5: UnknownInlinedFun (fcxml.c:2606)
==2726510==by 0x49FA2F5: FcEndElement (fcxml.c:3156)

In any case, I don't think libsl should call FcFini because we don't
know if the user is done with fontconfig or not and the FcFini
documentation states [0]:

| Frees all data structures allocated by previous calls to fontconfig
| functions. Fontconfig returns to an uninitialized state, requiring a new
| call to one of the FcInit functions before any other fontconfig function
| may be called.

The last line (requiring a new...before any other functions may be called)
makes me question if it's even okay that fontconfig functions are being
called without initializing the library.

ST calls FcInit during setup [1], dmenu/dwm doesn't. Maybe they should ?

I'm not really sure, the fontconfig documentation doesn't seem to say
anywhere (aside from that line in FcFini docs) weather initialization is
required or not.

[0]: 
https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcfini.html
[1]: https://git.suckless.org/st/file/x.c.html#l1144

- NRK



Re: [dev] [libsl][bug] Call FcFini on cleanup for projects calling FcIni

2022-10-30 Thread Anskrevy

On 10/30/22 10:47, NRK wrote:

On Thu, Oct 27, 2022 at 01:19:28PM -0700, Anskrevy wrote:

Any program using libsl, or calling FcIni (directly or indirectly), that
does not call FcFini results in a small memory leak. dwm and dmenu are
effected by this.


I do not see any call to FcInit in libsl, nor do I see any such call in
dmenu/dwm. Running dmenu master branch under leak-sanitizer doesn't show
any leaks related to fontconfig (v2.13.1) either.

How exactly did you detect this leak? And are you sure this is a problem
on libsl/dmenu/dwm side and not the library itself leaking things?

- NRK

I was mistaken. I thought that one of the Fc calls in drw.c was 
indirectly calling FcInit but after searching the fontconfig code base I 
don't think that is the case.


As for how I found the leak I was using valgrind. You can try out this 
small program.


Here is the Makefile
https://gist.github.com/Anskrevy/52fa06719ad204cc99eb190bf20ddd84

Here is the source code
https://gist.github.com/Anskrevy/c33a4ea0455a592d04b8a917eaf6737c

And here is my valgrind output
https://gist.github.com/Anskrevy/b981453fb7fbe3fb410ac1dd883d23ad

Adding a call to FcFini in the x_cleanup function results in zero bytes 
being lost.


I got similar output when using valgrind on dmenu. I believe it would be 
the same with dwm but have yet to test it out yet.




Re: [dev] [libsl][bug] Call FcFini on cleanup for projects calling FcIni

2022-10-30 Thread NRK
On Thu, Oct 27, 2022 at 01:19:28PM -0700, Anskrevy wrote:
> Any program using libsl, or calling FcIni (directly or indirectly), that
> does not call FcFini results in a small memory leak. dwm and dmenu are
> effected by this.

I do not see any call to FcInit in libsl, nor do I see any such call in
dmenu/dwm. Running dmenu master branch under leak-sanitizer doesn't show
any leaks related to fontconfig (v2.13.1) either.

How exactly did you detect this leak? And are you sure this is a problem
on libsl/dmenu/dwm side and not the library itself leaking things?

- NRK