For the below code
bool CustomCairoRenderer::renderString(const std::string &str,const Coordinates &renderFrom)
{
if(cairo_surface_status(_surface)!= CAIRO_STATUS_SUCCESS||cairo_status(_cr)!=CAIRO_STATUS_SUCCESS)
{
return false;
}
cairo_move_to (_cr,renderFrom.x, renderFrom.y);
cairo_show_text (_cr, str.c_str());
return true;
}
I'm getting the following valgrind error
==919== HEAP SUMMARY:
==919== in use at exit: 578,997 bytes in 4,390 blocks
==919== total heap usage: 20,456 allocs, 16,066 frees, 5,505,886
bytes allocated
==919==
==919== 288 (256 direct, 32 indirect) bytes in 1 blocks are definitely lost in loss record 123 of 212
==919== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==919== by 0x670B0B9: ??? (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x670B829: ??? (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x670CD4A: ??? (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x671219B: ??? (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x7FB0A9B: ??? (in /lib/x86_64-linux- gnu/libexpat.so.1.6.0)
==919== by 0x7FB13AB: ??? (in /lib/x86_64-linux- gnu/libexpat.so.1.6.0)
==919== by 0x7FB2CCD: ??? (in /lib/x86_64-linux- gnu/libexpat.so.1.6.0)
==919== by 0x7FB3424: ??? (in /lib/x86_64-linux- gnu/libexpat.so.1.6.0)
==919== by 0x7FB572A: XML_ParseBuffer (in /lib/x86_64-linux- gnu/libexpat.so.1.6.0)
==919== by 0x671152A: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==919== by 0x6711836: FcConfigParseAndLoad (in /usr/lib/x86_64- linux-gnu/libfontconfig.so.1.9.0)
==919==
==919== 353 (256 direct, 97 indirect) bytes in 1 blocks are definitely lost in loss record 138 of 212
==919== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==919== by 0x670B0B9: ??? (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x670B829: ??? (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x670C47A: FcPatternDuplicate (in /usr/lib/x86_64-linux- gnu/libfontconfig.so.1.9.0)
==919== by 0x514BFB2: ??? (in /usr/lib/x86_64-linux- gnu/libcairo.so.2.11400.6)
==919== by 0x514C19D: ??? (in /usr/lib/x86_64-linux- gnu/libcairo.so.2.11400.6)
==919== by 0x5110107: cairo_toy_font_face_create (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6)
==919== by 0x50BFD6F: ??? (in /usr/lib/x86_64-linux- gnu/libcairo.so.2.11400.6)
==919== by 0x50C2C60: ??? (in /usr/lib/x86_64-linux- gnu/libcairo.so.2.11400.6)
==919== by 0x50BB0FF: ??? (in /usr/lib/x86_64-linux- gnu/libcairo.so.2.11400.6)
==919== by 0x50B5242: cairo_show_text (in /usr/lib/x86_64-linux- gnu/libcairo.so.2.11400.6)
==919== by 0x44A978: CustomCairoRenderer::renderString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Coordinates const&, ) (customcairorenderer.cpp:166)
==919==
==919== LEAK SUMMARY:
==919== definitely lost: 512 bytes in 2 blocks
==919== indirectly lost: 129 bytes in 5 blocks
==919== possibly lost: 0 bytes in 0 blocks
==919== still reachable: 578,356 bytes in 4,383 blocks
==919== suppressed: 0 bytes in 0 blocks
==919== Reachable blocks (those to which a pointer was found) are not shown.
This function particularly renders only the given string. The cairo/surface creation and destruction is done in the class constructor and destructor. Could anyone spot what I'm doing wrong in this code? I'm using cairo version 1.14.6 on Ubuntu 16.04LTS
Update: Seems like calling cairo_debug_reset_static_data ();
will suppress some errors as mentioned here. But now I'm facing another valgrind error from fontconfig , no idea how to fix it.
==4546== HEAP SUMMARY:
==4546== in use at exit: 489,708 bytes in 4,130 blocks
==4546== total heap usage: 24,149 allocs, 20,019 frees, 5,806,541 bytes allocated
==4546==
==4546== 288 (256 direct, 32 indirect) bytes in 1 blocks are definitely lost in loss record 88 of 132
==4546== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4546== by 0x670B0B9: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==4546== by 0x670B829: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==4546== by 0x670CD4A: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==4546== by 0x671219B: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==4546== by 0x7FB0A9B: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.6.0)
==4546== by 0x7FB13AB: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.6.0)
==4546== by 0x7FB2CCD: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.6.0)
==4546== by 0x7FB3424: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.6.0)
==4546== by 0x7FB572A: XML_ParseBuffer (in /lib/x86_64-linux-gnu/libexpat.so.1.6.0)
==4546== by 0x671152A: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==4546== by 0x6711836: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.9.0)
==4546==
==4546== LEAK SUMMARY:
==4546== definitely lost: 256 bytes in 1 blocks
==4546== indirectly lost: 32 bytes in 1 blocks
==4546== possibly lost: 0 bytes in 0 blocks
==4546== still reachable: 489,420 bytes in 4,128 blocks
==4546== suppressed: 0 bytes in 0 blocks
==4546== Reachable blocks (those to which a pointer was found) are not shown.
Seems like calling cairo_debug_reset_static_data (); will suppress some errors as mentioned here. But now I'm facing another valgrind error from fontconfig , no idea how to fix it.
Call FcFini()
(after cairo_debug_reset_static_data()
).