Memory Leaks in Libsecret

Hello, I’m trying to develop an Application in C, that uses the Libsecret Library for handling Password/ GNOME-Keyring related Stuff.

In my Program I have encountered Memory Leaks which I just can’t understand.

A simple Test Example would be:

#include <libsecret/secret.h>
#include <stdlib.h>
#include <stdio.h>

int main(){
    SecretService *service = NULL;
    SecretCollection *collection = NULL;
    GError *error = NULL;
    const gchar *collectionLabel = "test";
    
    service = secret_service_get_sync(SECRET_SERVICE_NONE,NULL,&error);
    if(error != NULL){
        printf("Error connecting to Secret Service %s",error->message);
        g_error_free(error);
        return 1;
    }
    collection = secret_collection_create_sync(
            service, collectionLabel,
            NULL,SECRET_COLLECTION_CREATE_NONE,
            NULL, &error);
    if (error != NULL){
        printf("Error creating new Collection: %s",error->message);
        g_error_free(error);
        g_object_unref(service);
        return 1;
    }
    g_object_unref(service);
    service = NULL;
    g_object_unref(collection);
    collection = NULL;
    return 0;
}

From the Documentation I get,
that I must free the returns of secret_service_get_sync and secret_collection_create_sync, which I as far as I understand it, do.

The Creation of a new collection seems to call secret_service_prompt in the background, but from

This function is called by other parts of this library to handle prompts for the various actions that can require prompting.

I would assume, that I don’t have to deal with this function myself and this is handled internally.

Howerver, when I compile my Test Application with gcc main.c -g -O0 -o main $(pkg-config --cflags --libs libsecret-1)
Which as far as I can tell is the correct way to Memory check GLib Applications per this Documentation Page.

and then Test the Memory with

G_DEBUG=gc-friendly G_SLICE=always-malloc \
valgrind \
--leak-check=full \
--track-origins=yes \
--suppressions=/usr/share/glib-2.0/valgrind/glib.supp \
--suppresions=/usr/share/gtk-4.0/valgrind/gtk.supp \
--show-leak-kinds=definite \
./main

I get

==29149== Memcheck, a memory error detector
==29149== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==29149== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==29149== Command: ./main
==29149== 
==29149== 
==29149== HEAP SUMMARY:
==29149==     in use at exit: 145,166 bytes in 1,812 blocks
==29149==   total heap usage: 9,631 allocs, 7,819 frees, 493,675 bytes allocated
==29149== 
==29149== 8 bytes in 1 blocks are definitely lost in loss record 60 of 1,359
==29149==    at 0x484DA83: calloc (vg_replace_malloc.c:1328)
==29149==    by 0x49EC615: g_malloc0 (gmem.c:133)
==29149==    by 0x49EC93B: g_malloc0_n (gmem.c:414)
==29149==    by 0x4EBA023: weak_ref_new (gdbusproxy.c:112)
==29149==    by 0x4EBD1EE: async_initable_init_first (gdbusproxy.c:1713)
==29149==    by 0x4EBD7F9: initable_init (gdbusproxy.c:1883)
==29149==    by 0x4DC8368: g_initable_init (ginitable.c:129)
==29149==    by 0x4DC85E5: g_initable_new_valist (ginitable.c:249)
==29149==    by 0x4DC8434: g_initable_new (ginitable.c:163)
==29149==    by 0x48BEEA4: _secret_prompt_instance (secret-prompt.c:96)
==29149==    by 0x48CBDB6: on_create_collection_called (secret-paths.c:1683)
==29149==    by 0x4E189C4: g_task_return_now (gtask.c:1361)
==29149== 
==29149== 8 bytes in 1 blocks are definitely lost in loss record 61 of 1,359
==29149==    at 0x484DA83: calloc (vg_replace_malloc.c:1328)
==29149==    by 0x49EC615: g_malloc0 (gmem.c:133)
==29149==    by 0x49EC93B: g_malloc0_n (gmem.c:414)
==29149==    by 0x4EBA023: weak_ref_new (gdbusproxy.c:112)
==29149==    by 0x4EBD2A5: async_initable_init_first (gdbusproxy.c:1729)
==29149==    by 0x4EBD7F9: initable_init (gdbusproxy.c:1883)
==29149==    by 0x4DC8368: g_initable_init (ginitable.c:129)
==29149==    by 0x4DC85E5: g_initable_new_valist (ginitable.c:249)
==29149==    by 0x4DC8434: g_initable_new (ginitable.c:163)
==29149==    by 0x48BEEA4: _secret_prompt_instance (secret-prompt.c:96)
==29149==    by 0x48CBDB6: on_create_collection_called (secret-paths.c:1683)
==29149==    by 0x4E189C4: g_task_return_now (gtask.c:1361)
==29149== 
==29149== LEAK SUMMARY:
==29149==    definitely lost: 16 bytes in 2 blocks
==29149==    indirectly lost: 0 bytes in 0 blocks
==29149==      possibly lost: 912 bytes in 3 blocks
==29149==    still reachable: 127,790 bytes in 1,656 blocks
==29149==         suppressed: 0 bytes in 0 blocks
==29149== Reachable blocks (those to which a pointer was found) are not shown.
==29149== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==29149== 
==29149== For lists of detected and suppressed errors, rerun with: -s
==29149== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0)

I’m not sure if the GTK is the correct suppression file for the GTK Version that Libsecret/ GLib is using. I personally could not find Documentation regarding this. I just build GTK 4 from Scratch because on my Linux Mint 21.3 GTK-3-24 was the newest avaiable Version.

I know there is a difference between GTK 3 and 4, but in the Documentation for using Valgrind with GLib they used GTK4 too. How can I find out if I am actually using GTK4 and not actually GTK3?

For completion here my Environment Information

$ inxi -Fxxxpmrz
System:
  Kernel: 6.5.0-41-generic x86_64 bits: 64 compiler: N/A
    Desktop: Cinnamon 6.0.4 tk: GTK 3.24.33 wm: muffin vt: 7 dm: LightDM 1.30.0
    Distro: Linux Mint 21.3 Virginia base: Ubuntu 22.04 jammy
Machine:
  Type: Desktop Mobo: ASUSTeK model: PRIME B350-PLUS v: Rev X.0x
    serial: <superuser required> UEFI: American Megatrends v: 6203
    date: 07/27/2023
Memory:
  RAM: total: 15.52 GiB used: 2.83 GiB (18.3%)
  RAM Report:
    permissions: Unable to run dmidecode. Root privileges required.
CPU:
  Info: 6-core model: AMD Ryzen 5 3600X bits: 64 type: MT MCP smt: enabled
    arch: Zen 2 rev: 0 cache: L1: 384 KiB L2: 3 MiB L3: 32 MiB
  Speed (MHz): avg: 2320 high: 3800 min/max: 2200/4409 boost: enabled
    cores: 1: 3800 2: 2200 3: 2200 4: 2200 5: 2200 6: 2200 7: 2200 8: 2053
    9: 2200 10: 2196 11: 2196 12: 2200 bogomips: 91034
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
Graphics:
  Device-1: NVIDIA TU116 [GeForce GTX 1660] vendor: Micro-Star MSI
    driver: nvidia v: 545.29.06 pcie: speed: 2.5 GT/s lanes: 16 ports:
    active: none off: DP-2,DP-3 empty: DP-1,HDMI-A-1 bus-ID: 08:00.0
    chip-ID: 10de:2184 class-ID: 0300
  Device-2: Jieli USB PHY 2.0 type: USB driver: snd-usb-audio,uvcvideo
    bus-ID: 5-1.4:5 chip-ID: 1224:2a25 class-ID: 0102
  Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: nvidia
    unloaded: fbdev,modesetting,nouveau,vesa gpu: nvidia display-ID: :0
    screens: 1
  Screen-1: 0 s-res: 3840x1080 s-dpi: 81 s-size: 1204x343mm (47.4x13.5")
    s-diag: 1252mm (49.3")
  Monitor-1: DP-2 pos: primary,left res: 1920x1080 hz: 60 dpi: 82
    size: 598x336mm (23.5x13.2") diag: 686mm (27")
  Monitor-2: DP-4 pos: primary,right res: 1920x1080 dpi: 82
    size: 598x336mm (23.5x13.2") diag: 686mm (27")
  OpenGL: renderer: NVIDIA GeForce GTX 1660/PCIe/SSE2
    v: 4.6.0 NVIDIA 545.29.06 direct render: Yes
Audio:
  Device-1: NVIDIA TU116 High Definition Audio vendor: Micro-Star MSI
    driver: snd_hda_intel v: kernel pcie: speed: 8 GT/s lanes: 16
    bus-ID: 08:00.1 chip-ID: 10de:1aeb class-ID: 0403
  Device-2: AMD Starship/Matisse HD Audio vendor: ASUSTeK
    driver: snd_hda_intel v: kernel pcie: speed: 16 GT/s lanes: 16
    bus-ID: 0a:00.4 chip-ID: 1022:1487 class-ID: 0403
  Device-3: Jieli USB PHY 2.0 type: USB driver: snd-usb-audio,uvcvideo
    bus-ID: 5-1.4:5 chip-ID: 1224:2a25 class-ID: 0102
  Device-4: C-Media Auna Mic CM900 type: USB
    driver: hid-generic,snd-usb-audio,usbhid bus-ID: 5-2:3 chip-ID: 0d8c:0134
    class-ID: 0300
  Sound Server-1: ALSA v: k6.5.0-41-generic running: yes
  Sound Server-2: PulseAudio v: 15.99.1 running: yes
  Sound Server-3: PipeWire v: 0.3.48 running: yes
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    vendor: ASUSTeK PRIME B450M-A driver: r8169 v: kernel pcie: speed: 2.5 GT/s
    lanes: 1 port: f000 bus-ID: 04:00.0 chip-ID: 10ec:8168 class-ID: 0200
  IF: enp4s0 state: up speed: 100 Mbps duplex: full mac: <filter>
  IF-ID-1: virbr0 state: down mac: <filter>
Bluetooth:
  Device-1: Cambridge Silicon Radio Bluetooth Dongle (HCI mode) type: USB
    driver: btusb v: 0.8 bus-ID: 5-1.2:4 chip-ID: 0a12:0001 class-ID: e001
  Report: hciconfig ID: hci0 rfk-id: 0 state: up address: <filter>
    bt-v: 2.1 lmp-v: 4.0 sub-v: 22bb hci-v: 4.0 rev: 22bb
Drives:
  Local Storage: total: 2.06 TiB used: 1.03 TiB (50.1%)
  ID-1: /dev/nvme0n1 vendor: Seagate model: XPG GAMMIX S11 Pro
    size: 953.87 GiB speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter>
    rev: 42AZS6AC temp: 35.9 C scheme: GPT
  ID-2: /dev/sda vendor: Toshiba model: TR200 size: 223.57 GiB
    speed: 6.0 Gb/s type: SSD serial: <filter> rev: 12.6 scheme: GPT
  ID-3: /dev/sdb vendor: Samsung model: SSD 870 QVO 1TB size: 931.51 GiB
    speed: 6.0 Gb/s type: SSD serial: <filter> rev: 2B6Q scheme: MBR
Partition:
  ID-1: / size: 937.33 GiB used: 526.74 GiB (56.2%) fs: ext4
    dev: /dev/nvme0n1p3
  ID-2: /boot/efi size: 512 MiB used: 31.7 MiB (6.2%) fs: vfat
    dev: /dev/nvme0n1p2
  ID-3: /home/meiko size: 937.33 GiB used: 526.74 GiB (56.2%) fs: ecryptfs
    source: ERR-102
  ID-4: /mnt/AB9D-ECD3 size: 931.28 GiB used: 4.03 GiB (0.4%) fs: vfat
    dev: /dev/sdb1
Swap:
  ID-1: swap-1 type: file size: 2 GiB used: 256 KiB (0.0%) priority: -2
    file: /swapfile
Sensors:
  System Temperatures: cpu: N/A mobo: N/A gpu: nvidia temp: 32 C
  Fan Speeds (RPM): N/A gpu: nvidia fan: 46%
Repos:
  Packages: 3344 apt: 3317 flatpak: 27
  No active apt repos in: /etc/apt/sources.list
  Active apt repos in: /etc/apt/sources.list.d/brave-browser-release.list
    1: deb [arch=amd64 signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main
  Active apt repos in: /etc/apt/sources.list.d/cran.list
    1: deb [signed-by=/usr/share/keyrings/cran.gpg] https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/
  Active apt repos in: /etc/apt/sources.list.d/ddebs.list
    1: deb http://ddebs.ubuntu.com jammy main restricted universe multiverse
    2: deb http://ddebs.ubuntu.com jammy-updates main restricted universe multiverse
    3: deb http://ddebs.ubuntu.com jammy-proposed main restricted universe multiverse
  Active apt repos in: /etc/apt/sources.list.d/gnome-terminator-ppa-jammy.list
    1: deb [signed-by=/etc/apt/keyrings/gnome-terminator-ppa-jammy.gpg] https://ppa.launchpadcontent.net/gnome-terminator/ppa/ubuntu jammy main
  Active apt repos in: /etc/apt/sources.list.d/google-chrome.list
    1: deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main
  Active apt repos in: /etc/apt/sources.list.d/graphics-drivers-ppa-jammy.list
    1: deb [signed-by=/etc/apt/keyrings/graphics-drivers-ppa-jammy.gpg] https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy main
  Active apt repos in: /etc/apt/sources.list.d/lunarg-vulkan-1.3.239-jammy.list
    1: deb https://packages.lunarg.com/vulkan/1.3.239 jammy main
    2: deb-src https://packages.lunarg.com/vulkan/1.3.239 jammy main
  Active apt repos in: /etc/apt/sources.list.d/neovim-ppa-stable-jammy.list
    1: deb [signed-by=/etc/apt/keyrings/neovim-ppa-stable-jammy.gpg] https://ppa.launchpadcontent.net/neovim-ppa/stable/ubuntu jammy main
  Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list
    1: deb https://ftp.fau.de/mint/packages virginia main upstream import backport
    2: deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
    3: deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
    4: deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
    5: deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
  Active apt repos in: /etc/apt/sources.list.d/onedrive.list
    1: deb [arch=amd64 signed-by=/usr/share/keyrings/obs-onedrive.gpg] https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_22.04/ ./
  Active apt repos in: /etc/apt/sources.list.d/phoerious-keepassxc-jammy.list
    1: deb [signed-by=/etc/apt/keyrings/phoerious-keepassxc-jammy.gpg] https://ppa.launchpadcontent.net/phoerious/keepassxc/ubuntu jammy main
  Active apt repos in: /etc/apt/sources.list.d/signal-xenial.list
    1: deb [arch=amd64 signed-by=/usr/share/keyrings/signal-desktop-keyring.gpg] https://updates.signal.org/desktop/apt xenial main
  Active apt repos in: /etc/apt/sources.list.d/spotify.list
    1: deb http://repository.spotify.com stable non-free
  Active apt repos in: /etc/apt/sources.list.d/teams.list
    1: deb [arch=amd64] https://packages.microsoft.com/repos/ms-teams stable main
  Active apt repos in: /etc/apt/sources.list.d/teamviewer.list
    1: deb [signed-by=/usr/share/keyrings/teamviewer-keyring.gpg] https://linux.teamviewer.com/deb stable main
  Active apt repos in: /etc/apt/sources.list.d/virtualbox.list
    1: deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian jammy contrib
  Active apt repos in: /etc/apt/sources.list.d/vscode.list
    1: deb [arch=amd64,arm64,armhf] http://packages.microsoft.com/repos/code stable main
Info:
  Processes: 342 Uptime: 36m wakeups: 0 Init: systemd v: 249 runlevel: 5
  Compilers: gcc: 11.4.0 alt: 11/12 clang: 14.0.0-1ubuntu1.1 Shell: Bash
  v: 5.1.16 running-in: gnome-terminal inxi: 3.3.13

Which somehow still shows GTK 3.24.33
I also tried to include the suppresion file for both GTK Versions, but this didn’t help.

If you need more Information or have an Idea, I will try to answer as fast as I can.

I was going to say “this needs a bug report” but I see you already created one.