g_object_unref() memory leak
OS:
- centos 8
- fedora 32
My test code (tpol.c
):
#include <polkit/polkit.h>
int main(int argc, char *argv[])
{
int i;
for (i = 0; i < 60; i++)
{
PolkitAuthority *pa = NULL;
pa = polkit_authority_get_sync(NULL, NULL);
g_object_unref(pa);
sleep(1);
}
return 0;
}
compile options:
gcc -g `pkg-config --cflags glib-2.0 polkit-gobject-1` -o tpolkit tpol.c `pkg-config --libs glib-2.0 polkit-gobject-1`
valgrind options: valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt --num-callers=30 ./tpolkit
result:
==2765== LEAK SUMMARY:
==2765== definitely lost: 0 bytes in 0 blocks
==2765== indirectly lost: 0 bytes in 0 blocks
==2765== possibly lost: 2,416 bytes in 26 blocks
==2765== still reachable: 141,686 bytes in 2,154 blocks
==2765== of which reachable via heuristic:
==2765== length64 : 832 bytes in 16 blocks
==2765== newarray : 1,728 bytes in 28 blocks
==2765== suppressed: 0 bytes in 0 blocks
==2765==
==2765== ERROR SUMMARY: 26 errors from 26 contexts (suppressed: 0 from 0)
If run in an infinite loop, memory keeps leaking.
How I can un-allocate PolkitAuthority
memory?
The original issue was associated with pcsc-lite daemon (pcscd
): https://github.com/LudovicRousseau/PCSC/issues/87