phillbush / xfiles

Configurable and simple file manager for X11
MIT License
97 stars 3 forks source link

fix memory leaks #15

Closed alpheratz0 closed 1 year ago

alpheratz0 commented 1 year ago

There's a memory leak left to fix, I think that you need to call FcFini inside closewidget, see Alan Coopersmith's reply here

Before ```valgrind ==12775== Memcheck, a memory error detector ==12775== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==12775== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info ==12775== Command: ./xfiles ==12775== Parent PID: 719 ==12775== ==12775== ==12775== HEAP SUMMARY: ==12775== in use at exit: 380,274 bytes in 11,022 blocks ==12775== total heap usage: 39,734 allocs, 28,712 frees, 30,495,195 bytes allocated ==12775== ==12775== 9 bytes in 1 blocks are definitely lost in loss record 11 of 321 ==12775== at 0x4841888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12775== by 0x4AEB81E: strdup (strdup.c:42) ==12775== by 0x1175F5: estrdup (util.c:57) ==12775== by 0x10E23D: diropen (xfiles.c:518) ==12775== by 0x10F097: main (xfiles.c:849) ==12775== ==12775== 23 bytes in 1 blocks are definitely lost in loss record 37 of 321 ==12775== at 0x4841888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12775== by 0x4AEB81E: strdup (strdup.c:42) ==12775== by 0x1175F5: estrdup (util.c:57) ==12775== by 0x10D97F: diropen (xfiles.c:454) ==12775== by 0x10F097: main (xfiles.c:849) ==12775== ==12775== 160 bytes in 1 blocks are definitely lost in loss record 174 of 321 ==12775== at 0x4841888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12775== by 0x4902D20: XCreateGC (in /usr/lib/libX11.so.6.4.0) ==12775== by 0x11319C: initwidget (widget.c:1255) ==12775== by 0x10EF7D: main (xfiles.c:833) ==12775== ==12775== 302 (256 direct, 46 indirect) bytes in 1 blocks are definitely lost in loss record 192 of 321 ==12775== at 0x4841888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12775== by 0x489AF25: FcPatternObjectInsertElt (fcpat.c:525) ==12775== by 0x489F180: FcPatternObjectAddWithBinding (fcpat.c:711) ==12775== by 0x48AD079: UnknownInlinedFun (fcpat.c:1258) ==12775== by 0x48AD079: UnknownInlinedFun (fcxml.c:3109) ==12775== by 0x48AD079: FcEndElement (fcxml.c:3234) ==12775== by 0x4D1263E: doContent (xmlparse.c:3056) ==12775== by 0x4D0FC13: UnknownInlinedFun (xmlparse.c:2621) ==12775== by 0x4D0FC13: doProlog (xmlparse.c:4902) ==12775== by 0x4D117EC: prologProcessor (xmlparse.c:4607) ==12775== by 0x4D158E9: XML_ParseBuffer (xmlparse.c:2018) ==12775== by 0x48A77E4: FcConfigParseAndLoadFromMemoryInternal.lto_priv.0 (fcxml.c:3544) ==12775== by 0x48A8136: _FcConfigParse.lto_priv.0 (fcxml.c:3679) ==12775== by 0x48A8319: UnknownInlinedFun (fcxml.c:3447) ==12775== by 0x48A8319: _FcConfigParse.lto_priv.0 (fcxml.c:3638) ==12775== by 0x48AB2F5: UnknownInlinedFun (fcxml.c:2606) ==12775== by 0x48AB2F5: FcEndElement (fcxml.c:3156) ==12775== ==12775== LEAK SUMMARY: ==12775== definitely lost: 448 bytes in 4 blocks ==12775== indirectly lost: 46 bytes in 2 blocks ==12775== possibly lost: 0 bytes in 0 blocks ==12775== still reachable: 379,780 bytes in 11,016 blocks ==12775== suppressed: 0 bytes in 0 blocks ==12775== Reachable blocks (those to which a pointer was found) are not shown. ==12775== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==12775== ==12775== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0) ```
After ```valgrind ==12197== Memcheck, a memory error detector ==12197== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==12197== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info ==12197== Command: ./xfiles ==12197== Parent PID: 719 ==12197== ==12197== ==12197== HEAP SUMMARY: ==12197== in use at exit: 380,082 bytes in 11,019 blocks ==12197== total heap usage: 26,891 allocs, 15,872 frees, 13,352,266 bytes allocated ==12197== ==12197== 302 (256 direct, 46 indirect) bytes in 1 blocks are definitely lost in loss record 189 of 318 ==12197== at 0x4841888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==12197== by 0x489AF25: FcPatternObjectInsertElt (fcpat.c:525) ==12197== by 0x489F180: FcPatternObjectAddWithBinding (fcpat.c:711) ==12197== by 0x48AD079: UnknownInlinedFun (fcpat.c:1258) ==12197== by 0x48AD079: UnknownInlinedFun (fcxml.c:3109) ==12197== by 0x48AD079: FcEndElement (fcxml.c:3234) ==12197== by 0x4D1263E: doContent (xmlparse.c:3056) ==12197== by 0x4D0FC13: UnknownInlinedFun (xmlparse.c:2621) ==12197== by 0x4D0FC13: doProlog (xmlparse.c:4902) ==12197== by 0x4D117EC: prologProcessor (xmlparse.c:4607) ==12197== by 0x4D158E9: XML_ParseBuffer (xmlparse.c:2018) ==12197== by 0x48A77E4: FcConfigParseAndLoadFromMemoryInternal.lto_priv.0 (fcxml.c:3544) ==12197== by 0x48A8136: _FcConfigParse.lto_priv.0 (fcxml.c:3679) ==12197== by 0x48A8319: UnknownInlinedFun (fcxml.c:3447) ==12197== by 0x48A8319: _FcConfigParse.lto_priv.0 (fcxml.c:3638) ==12197== by 0x48AB2F5: UnknownInlinedFun (fcxml.c:2606) ==12197== by 0x48AB2F5: FcEndElement (fcxml.c:3156) ==12197== ==12197== LEAK SUMMARY: ==12197== definitely lost: 256 bytes in 1 blocks ==12197== indirectly lost: 46 bytes in 2 blocks ==12197== possibly lost: 0 bytes in 0 blocks ==12197== still reachable: 379,780 bytes in 11,016 blocks ==12197== suppressed: 0 bytes in 0 blocks ==12197== Reachable blocks (those to which a pointer was found) are not shown. ==12197== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==12197== ==12197== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) ```