Fix collect sessions paths leak
There's a small strings leak in collect_sessions
, this can be easily tested with:
valgrind --leak-check=full --suppressions=/usr/share/glib-2.0/valgrind/glib.supp gjs -c "imports.gi.Gdm.get_session_ids()"
==26760== Memcheck, a memory error detector
==26760== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==26760== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==26760== Command: gjs -c imports.gi.Gdm.get_session_ids()
==26760==
==26760== Warning: set address range perms: large range [0x10cbc4df6000, 0x10cc04df6000) (noaccess)
==26760== Warning: set address range perms: large range [0x10cbc4df6000, 0x10cc04df6000) (noaccess)
==26760==
==26760== HEAP SUMMARY:
==26760== in use at exit: 98,189 bytes in 1,151 blocks
==26760== total heap usage: 16,055 allocs, 14,904 frees, 6,010,354 bytes allocated
==26760==
==26760== 384 bytes in 9 blocks are definitely lost in loss record 963 of 991
==26760== at 0x483AD4B: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==26760== by 0x4AC36F6: g_realloc (gmem.c:164)
==26760== by 0x4AE0616: g_string_maybe_expand (gstring.c:102)
==26760== by 0x4AE0949: g_string_insert_len (gstring.c:486)
==26760== by 0x4AE0949: g_string_insert_len (gstring.c:426)
==26760== by 0x4AA80DD: g_build_path_va (gfileutils.c:1766)
==26760== by 0x4AA9524: g_build_filename_va (gfileutils.c:1987)
==26760== by 0x4AA9524: g_build_filename (gfileutils.c:2069)
==26760== by 0xBF3D2A7: collect_sessions (gdm-sessions.c:260)
==26760== by 0xBF3D5A4: gdm_get_session_ids (gdm-sessions.c:328)
==26760== by 0x529081D: ffi_call_unix64 (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.4)
==26760== by 0x52901EE: ffi_call (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.4)
==26760== by 0x4BE0AB7: ??? (function.cpp:1107)
==26760== by 0x4BE20C5: ??? (function.cpp:1439)
==26760==
==26760== 480 bytes in 9 blocks are definitely lost in loss record 964 of 991
==26760== at 0x483AD4B: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==26760== by 0x4AC36F6: g_realloc (gmem.c:164)
==26760== by 0x4AE0616: g_string_maybe_expand (gstring.c:102)
==26760== by 0x4AE0949: g_string_insert_len (gstring.c:486)
==26760== by 0x4AE0949: g_string_insert_len (gstring.c:426)
==26760== by 0x4AA80DD: g_build_path_va (gfileutils.c:1766)
==26760== by 0x4AA9524: g_build_filename_va (gfileutils.c:1987)
==26760== by 0x4AA9524: g_build_filename (gfileutils.c:2069)
==26760== by 0xBF3D31F: collect_sessions (gdm-sessions.c:274)
==26760== by 0xBF3D5A4: gdm_get_session_ids (gdm-sessions.c:328)
==26760== by 0x529081D: ffi_call_unix64 (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.4)
==26760== by 0x52901EE: ffi_call (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.4)
==26760== by 0x4BE0AB7: ??? (function.cpp:1107)
==26760== by 0x4BE20C5: ??? (function.cpp:1439)
==26760==
==26760== LEAK SUMMARY:
==26760== definitely lost: 864 bytes in 18 blocks
==26760== indirectly lost: 0 bytes in 0 blocks
==26760== possibly lost: 0 bytes in 0 blocks
==26760== still reachable: 60,820 bytes in 457 blocks
==26760== of which reachable via heuristic:
==26760== length64 : 896 bytes in 20 blocks
==26760== newarray : 1,648 bytes in 23 blocks
==26760== suppressed: 35,697 bytes in 669 blocks
==26760== Reachable blocks (those to which a pointer was found) are not shown.
==26760== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==26760==
==26760== For counts of detected and suppressed errors, rerun with: -v
==26760== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 21 from 21)
So make sure that we free any temporary string on return.