<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Static pointers leaks"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=83770">83770</a>
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>fontconfig-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Static pointers leaks
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>freedesktop@behdad.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>major
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>xauoyero@gmail.com
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>2.11
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>library
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>fontconfig
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=106142" name="attach_106142" title="Fix memory leaks and release allocated memory for some pointers clearly in FcFini.">attachment 106142</a> <a href="attachment.cgi?id=106142&action=edit" title="Fix memory leaks and release allocated memory for some pointers clearly in FcFini.">[details]</a></span>
Fix memory leaks and release allocated memory for some pointers clearly in
FcFini.

1. The memory allocated for userconf, userdir and other_types is not released
after FcFini was called. 
2. The memory allocated for ot->object.object in Function
_FcObjectLookupOtherTypeByName was not released before ot was released.

The ot memory leak was fixed in the attachment. And two fini functions were
added to FcFini so that we can free the memory clearly. My patch is just a
quick workaround for these problems and I am not sure whether this patch breaks
your infrastructure here. 


Test code for current mask branch:
#include <stdio.h>
#include <fontconfig/fontconfig.h>
int main(int argc, char **argv)
{
    FcInit();
    printf("%d\n", FcGetVersion());
    FcFini();
    return 0;
}

valgrind output:

$ valgrind --leak-check=full --show-leak-kinds=all ./test_fontconfig

==15109== Memcheck, a memory error detector
==15109== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==15109== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==15109== Command: ./test_fontconfig
==15109== 
...
21101
==15109== 
==15109== HEAP SUMMARY:
==15109==     in use at exit: 142 bytes in 6 blocks
==15109==   total heap usage: 16,372 allocs, 16,366 frees, 11,725,333 bytes
allocated
==15109== 
==15109== 32 bytes in 2 blocks are still reachable in loss record 1 of 4
==15109==    at 0x4029E7C: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==15109==    by 0x404E8F3: _FcObjectLookupOtherTypeByName (fcobjs.c:61)
==15109==    by 0x404EAA2: FcObjectLookupIdByName (fcobjs.c:101)
==15109==    by 0x4056FAF: FcEndElement (fcxml.c:2576)
==15109==    by 0x42E602D: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E7281: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E3FC0: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E5A31: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E8F8A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x4055948: FcConfigParseAndLoad (fcxml.c:3270)
==15109==    by 0x4055C00: FcConfigParseAndLoad (fcxml.c:3129)
==15109==    by 0x4055F46: FcEndElement (fcxml.c:2318)
==15109== 
==15109== 34 bytes in 1 blocks are still reachable in loss record 2 of 4
==15109==    at 0x4029E7C: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==15109==    by 0x41D1420: strdup (strdup.c:43)
==15109==    by 0x40572FE: FcEndElement (fcxml.c:2299)
==15109==    by 0x42E602D: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E7281: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E3FC0: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E5A31: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E8F8A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x4055948: FcConfigParseAndLoad (fcxml.c:3270)
==15109==    by 0x4055C00: FcConfigParseAndLoad (fcxml.c:3129)
==15109==    by 0x4055F46: FcEndElement (fcxml.c:2318)
==15109==    by 0x42E602D: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109== 
==15109== 38 bytes in 1 blocks are still reachable in loss record 3 of 4
==15109==    at 0x4029E7C: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==15109==    by 0x41D1420: strdup (strdup.c:43)
==15109==    by 0x4057337: FcEndElement (fcxml.c:2305)
==15109==    by 0x42E602D: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E7281: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E3FC0: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E5A31: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E8F8A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x4055948: FcConfigParseAndLoad (fcxml.c:3270)
==15109==    by 0x4055C00: FcConfigParseAndLoad (fcxml.c:3129)
==15109==    by 0x4055F46: FcEndElement (fcxml.c:2318)
==15109==    by 0x42E602D: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109== 
==15109== 38 bytes in 2 blocks are still reachable in loss record 4 of 4
==15109==    at 0x4029E7C: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==15109==    by 0x41D1420: strdup (strdup.c:43)
==15109==    by 0x404E907: _FcObjectLookupOtherTypeByName (fcobjs.c:65)
==15109==    by 0x404EAA2: FcObjectLookupIdByName (fcobjs.c:101)
==15109==    by 0x4056FAF: FcEndElement (fcxml.c:2576)
==15109==    by 0x42E602D: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E7281: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E3FC0: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E5A31: ??? (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x42E8F8A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.6.0)
==15109==    by 0x4055948: FcConfigParseAndLoad (fcxml.c:3270)
==15109==    by 0x4055C00: FcConfigParseAndLoad (fcxml.c:3129)
==15109== 
==15109== LEAK SUMMARY:
==15109==    definitely lost: 0 bytes in 0 blocks
==15109==    indirectly lost: 0 bytes in 0 blocks
==15109==      possibly lost: 0 bytes in 0 blocks
==15109==    still reachable: 142 bytes in 6 blocks
==15109==         suppressed: 0 bytes in 0 blocks
==15109== 
==15109== For counts of detected and suppressed errors, rerun with: -v
==15109== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>