Valgrind reports memory 'possibly lost' when using glib data types

只愿长相守 提交于 2019-11-28 05:53:15

GLib has a few features that confuse Valgrind.

One is memory pools (g_slice in newer glib, "mem chunks" in older). These are specialized allocators used for small objects such as list nodes. You can use this to disable the slice allocator: G_SLICE=always-malloc valgrind myprogram

A second issue is that sometimes GLib would avoid initializing new memory or keep dead pointers in freed slices/chunks. You can fix this with: G_DEBUG=gc-friendly valgrind myprogram

So together of course: G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind myprogram

A third issue is that GLib has global variables that are simply never freed but considered permanent program state. For example registered GType are never unloaded, and a few others. This is not fixable, but valgrind should show these global allocations as reachable, rather than as lost.

Guillaume

glib-2.12 is quite old.

Try getting glib-2.24, compile and install it (with --prefix=/usr/local/glib-2.24 for example) then use it to compile your application.

If you still have this, try to read the glib manual again :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!