How to correct read ini files using glib?

Hi!
I’m using GLIB to read ini files. I’ve created helper function to use along all parts of my program (written in C).
This is the function to read integer:

int ini_getInteger(char *ini_file, char *section, char *key, int def_value) {
    GKeyFile *localini;
    GError *error = NULL;
    int abc = 0;

    localini = g_key_file_new();

    if (g_key_file_load_from_file(localini, ini_file, G_KEY_FILE_KEEP_COMMENTS, &error) == FALSE) {
        mylog_log("Error loading ini file.\n");
        g_key_file_free(localini);
        if (error != NULL) {
            g_error_free(error);
        }
        return def_value;
    }

    abc = g_key_file_get_integer(localini, section, key, &error);    
    g_key_file_free(localini);

    if (error != NULL) {        
        if (error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND || error->code == G_KEY_FILE_ERROR_INVALID_VALUE || error->code == G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            g_error_free(error);
            return def_value;
        } else {
            g_error_free(error);
            return abc;
        }
    } else {
        return abc;
    }


}

And this is an example of use (from monitor.c):

           if (ini_getInteger(config_file, "server", "debug_level", 0) != debug_level) {
                debug_level = ini_getInteger(config_file, "server", "debug_level", 0);
            }

The function is working, I’m getting the correct value. The problem is that I’m getting memory leak too.
This is the output from valgrind:

==2505==
==2505== HEAP SUMMARY:
==2505==     in use at exit: 108,497 bytes in 785 blocks
==2505==   total heap usage: 13,086 allocs, 12,301 frees, 622,799 bytes allocated
==2505==
==2505== 184 (88 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 52 of 61
==2505==    at 0x6CA177F: malloc (vg_replace_malloc.c:299)
==2505==    by 0x72EB8D0: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==2505==    by 0x7303832: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==2505==    by 0x72D3D2D: g_hash_table_new_full (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==2505==    by 0x72BFCF0: g_get_language_names_with_category (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==2505==    by 0x72DB58B: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==2505==    by 0x72DD22C: g_key_file_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==2505==    by 0x11AB56: ini_getInteger (utils.c:459)
==2505==    by 0x10FFCD: thread_monitor (monitor.c:138)
==2505==    by 0x6CC7FA2: start_thread (pthread_create.c:486)
==2505==    by 0x75054CE: clone (clone.S:95)
==2505==
==2505== LEAK SUMMARY:
==2505==    definitely lost: 88 bytes in 1 blocks
==2505==    indirectly lost: 96 bytes in 2 blocks
==2505==      possibly lost: 0 bytes in 0 blocks
==2505==    still reachable: 108,313 bytes in 782 blocks
==2505==         suppressed: 0 bytes in 0 blocks
==2505== Reachable blocks (those to which a pointer was found) are not shown.
==2505== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2505==
==2505== For counts of detected and suppressed errors, rerun with: -v
==2505== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

What am I doing wrong?
GLIBC Version: 2.28

You are not using the suppression file that comes with glib which hides certain “one-off” leaks, see for example this discussion here: Feature Request: Enable compilation without memory leaks - #3 by mcatanzaro

Indeed. Run with valgrind --suppressions=/usr/share/glib-2.0/valgrind/glib.supp

Tks for quick reply!
But still getting the same memory leak, even using supression file. I’ve checked, supression file exists in the correct path, so I think it’s loaded as expected.
This is the command and full output:

jmaurin@Skynet:~/dev/v3/Server$ sudo valgrind --suppressions=/usr/share/glib-2.0/valgrind/glib.supp --leak-check=full --track-origins=yes ./dist/Debug/GNU-Linux/server
==10197== Memcheck, a memory error detector
==10197== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==10197== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==10197== Command: ./dist/Debug/GNU-Linux/server
==10197==
[2021-07-16 19:39:26]  Starting Rpi Server
[2021-07-16 19:39:26]  GLIBC Version: 2.28
[2021-07-16 19:39:26]  Loading configurations...
Initializing network services...
[2021-07-16 19:39:28]  Socket for CLIENTS created. Waiting for connections on port 33755
[2021-07-16 19:39:28] [thread_monitor]  Looking mutex m_client_list...
[2021-07-16 19:39:28] [thread_monitor]  Unlooking mutex m_client_list...
[2021-07-16 19:39:28] [thread_waitNewClients]  Socket is in non-blocking mode!
[2021-07-16 19:39:28]  *********** Updating Every 60 seconds ***********
[2021-07-16 19:39:28]  Socket for SERVERS created. Waiting for connections on port 33850
[2021-07-16 19:39:28]  Running database update for tracked flights..........[2021-07-16 19:39:28]  Server v2.0.0 (build 20210712110000)
[2021-07-16 19:39:28]  finished
[2021-07-16 19:39:28]  [MONITOR] Statistics:
[2021-07-16 19:39:28]  [MONITOR] Clients RPi connected: 0
[2021-07-16 19:39:28]  [MONITOR] Clients AAA connected: 0
[2021-07-16 19:39:28]  [MONITOR] Clients BBB connected: 0
[2021-07-16 19:39:28]  [MONITOR] Clients CCC connected: 0
[2021-07-16 19:39:28]  [MONITOR] Clients Other connected: 0
[2021-07-16 19:39:28]  [MONITOR] Total packets received: 0
[2021-07-16 19:39:28]  [MONITOR] Positions received: 0
[2021-07-16 19:39:28]  [MONITOR] Servers connected: 0
[2021-07-16 19:39:28]
[2021-07-16 19:39:41]  TCP Client (Server) requesting to connect...
[2021-07-16 19:39:41]  [Slot 0] New SERVER connection from IP 192.168.22.12, remote port 62987, socket: 5
[2021-07-16 19:39:41] [backend_thread_waitNewServers]  Slot do server: 0
^C[2021-07-16 19:39:44]  Interruption signal received, proceding to shutdown....
[2021-07-16 19:39:44] [thread_waitNewClients]  Exited newClients Successfull!
[2021-07-16 19:39:44] [thread_monitor]  Exiting monitor thread.
[2021-07-16 19:39:44] [backend_thread_handler_serverData]  Server [0] disconnected. Cleaning lists...
[2021-07-16 19:39:44] [thread_monitorTrackedFlight]  Exiting monitorTrackedFlight thread.
[2021-07-16 19:39:44]  Server at slot 0 disconnected.
[2021-07-16 19:39:44] [backend_thread_handler_serverData]  Exiting handlerServerData thread
[2021-07-16 19:39:44]  Exiting queue proccess for server 0.
[2021-07-16 19:39:46]  Server shutdown successfull
==10197==
==10197== HEAP SUMMARY:
==10197==     in use at exit: 110,143 bytes in 789 blocks
==10197==   total heap usage: 12,631 allocs, 11,842 frees, 615,974 bytes allocated
==10197==
==10197== 184 (88 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 54 of 65
==10197==    at 0x6CA177F: malloc (vg_replace_malloc.c:299)
==10197==    by 0x72EB8D0: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==10197==    by 0x7303832: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==10197==    by 0x72D3D2D: g_hash_table_new_full (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==10197==    by 0x72BFCF0: g_get_language_names_with_category (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==10197==    by 0x72DB58B: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==10197==    by 0x72DD22C: g_key_file_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==10197==    by 0x11AB82: ini_getInteger (utils.c:459)
==10197==    by 0x10FFCD: thread_monitor (monitor.c:138)
==10197==    by 0x6CC7FA2: start_thread (pthread_create.c:486)
==10197==    by 0x75054CE: clone (clone.S:95)
==10197==
==10197== LEAK SUMMARY:
==10197==    definitely lost: 88 bytes in 1 blocks
==10197==    indirectly lost: 96 bytes in 2 blocks
==10197==      possibly lost: 0 bytes in 0 blocks
==10197==    still reachable: 109,959 bytes in 786 blocks
==10197==         suppressed: 0 bytes in 0 blocks
==10197== Reachable blocks (those to which a pointer was found) are not shown.
==10197== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==10197==
==10197== For counts of detected and suppressed errors, rerun with: -v
==10197== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

The language names hash table should be added to the suppressions.

“Should be” you mean by dev team, right?
I could not find any other file in /usr/share/glib-2.0/valgrind/ path, only glib.supp file.

Or by you, if you feel like you want to contribute to GLib.

But, yes: the suppression file should be checked and, if needed, updated.

In the meantime, you can write your own additional suppression file and add it to the Valgrind command line (you can have multiple --suppressions arguments).

ok, I’ll look into this. I never used or created supression files before.

Tks

It’s already there in main:

{
        g-get-language_names-with-category-malloc
        Memcheck:Leak
        match-leak-kinds:reachable
        fun:malloc
        ...
        fun:g_get_language_names_with_category
}

{
        g-get-language_names-with-category-calloc
        Memcheck:Leak
        match-leak-kinds:reachable
        fun:calloc
        ...
        fun:g_get_language_names_with_category
}

{
        g-get-language_names-with-category-realloc
        Memcheck:Leak
        match-leak-kinds:reachable
        fun:realloc
        ...
        fun:g_get_language_names_with_category
}

@jmaurin, put those suppressions in a new .supp file and pass that to valgrind with another --suppressions argument and things should work.

I start to thinking that I’m really doing something wrong here :confused:
Still getting the same leak, even with the new suppression file.

Output from tests:

jmaurin@Skynet:~/dev/v3/Server$ cat /usr/share/glib-2.0/valgrind/jonis.supp
{
        g-get-language_names-with-category-malloc
        Memcheck:Leak
        match-leak-kinds:reachable
        fun:malloc
        ...
        fun:g_get_language_names_with_category
}

{
        g-get-language_names-with-category-calloc
        Memcheck:Leak
        match-leak-kinds:reachable
        fun:calloc
        ...
        fun:g_get_language_names_with_category
}

{
        g-get-language_names-with-category-realloc
        Memcheck:Leak
        match-leak-kinds:reachable
        fun:realloc
        ...
        fun:g_get_language_names_with_category
}
jmaurin@Skynet:~/dev/v3/Server$ make && sudo valgrind --suppressions=/usr/share/glib-2.0/valgrind/glib.supp --suppressions=/usr/share/glib-2.0/valgrind/jonis.supp --leak-check=full --track-origins=yes ./dist/Debug/GNU-Linux/server
protoc-c --c_out=. rbfeeder.proto
"make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/jmaurin/dev/v3/Server'
"make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/server
make[2]: Entering directory '/home/jmaurin/dev/v3/Server'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/backend_servers.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/backend_servers.o.d" -o build/Debug/GNU-Linux/backend_servers.o backend_servers.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/cmd.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/cmd.o.d" -o build/Debug/GNU-Linux/cmd.o cmd.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/monitor.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/monitor.o.d" -o build/Debug/GNU-Linux/monitor.o monitor.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/net_server.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/net_server.o.d" -o build/Debug/GNU-Linux/net_server.o net_server.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/proc_packets.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/proc_packets.o.d" -o build/Debug/GNU-Linux/proc_packets.o proc_packets.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/rbfeeder.pb-c.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/rbfeeder.pb-c.o.d" -o build/Debug/GNU-Linux/rbfeeder.pb-c.o rbfeeder.pb-c.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/rbserver.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/rbserver.o.d" -o build/Debug/GNU-Linux/rbserver.o rbserver.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/sharing_key.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/sharing_key.o.d" -o build/Debug/GNU-Linux/sharing_key.o sharing_key.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/user_stats.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/user_stats.o.d" -o build/Debug/GNU-Linux/user_stats.o user_stats.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/utils.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/utils.o.d" -o build/Debug/GNU-Linux/utils.o utils.c
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/weather.o.d"
gcc    -c -g -Wall -DBDTIME=\"20210712110000\" -DRBFEEDER_SERVER_VER_PRINT=\"2.0.0\" -D_DEFAULT_SOURCE -I/usr/include `pkg-config --cflags libprotobuf-c` `pkg-config --cflags glib-2.0` `pkg-config --cflags libpq` `pkg-config --cflags libmariadb` -std=c11  -MMD -MP -MF "build/Debug/GNU-Linux/weather.o.d" -o build/Debug/GNU-Linux/weather.o weather.c
mkdir -p dist/Debug/GNU-Linux
gcc     -o dist/Debug/GNU-Linux/server build/Debug/GNU-Linux/backend_servers.o build/Debug/GNU-Linux/cmd.o build/Debug/GNU-Linux/md5.o build/Debug/GNU-Linux/monitor.o build/Debug/GNU-Linux/net_server.o build/Debug/GNU-Linux/proc_packets.o build/Debug/GNU-Linux/rbfeeder.pb-c.o build/Debug/GNU-Linux/rbserver.o build/Debug/GNU-Linux/sharing_key.o build/Debug/GNU-Linux/user_stats.o build/Debug/GNU-Linux/utils.o build/Debug/GNU-Linux/weather.o -lpthread -ldl `pkg-config --libs libprotobuf-c` `pkg-config --libs glib-2.0` `pkg-config --libs libpq` `pkg-config --libs libmariadb`   -lrt
make[2]: Leaving directory '/home/jmaurin/dev/v3/Server'
make[1]: Leaving directory '/home/jmaurin/dev/v3/Server'
==25103== Memcheck, a memory error detector
==25103== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==25103== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==25103== Command: ./dist/Debug/GNU-Linux/server
==25103==
[2021-07-20 10:19:12]  GLIBC Version: 2.28
[2021-07-20 10:19:12]  Loading configurations...
(...)
^C[2021-07-20 10:19:21]  Interruption signal received, proceding to shutdown....
[2021-07-20 10:19:21] [net_thread_waitNewClients]  Exited newClients Successfull!
[2021-07-20 10:19:21] [cmd_thread_dbCmdQueue]  Exiting cmd_thread_dbCmdQueue thread
[2021-07-20 10:19:21] [thread_monitor]  Exiting monitor thread.
[2021-07-20 10:19:21] [thread_monitorTrackedFlight]  Exiting monitorTrackedFlight thread.
[2021-07-20 10:19:21] [weather_thread_saveWeatherToDatabase]  Number of weather packets in cache (for weather database): 0
[2021-07-20 10:19:22] [weather_thread_saveWeatherToDatabase]  Exiting weather thread.
[2021-07-20 10:19:24]  Server shutdown successfull
==25103==
==25103== HEAP SUMMARY:
==25103==     in use at exit: 108,498 bytes in 785 blocks
==25103==   total heap usage: 11,551 allocs, 10,766 frees, 641,796 bytes allocated
==25103==
==25103== 184 (88 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 52 of 61
==25103==    at 0x6CA777F: malloc (vg_replace_malloc.c:299)
==25103==    by 0x6D4A8D0: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==25103==    by 0x6D62832: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==25103==    by 0x6D32D2D: g_hash_table_new_full (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==25103==    by 0x6D1ECF0: g_get_language_names_with_category (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==25103==    by 0x6D3A58B: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==25103==    by 0x6D3C22C: g_key_file_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==25103==    by 0x11EAF4: ini_getInteger (utils.c:459)
==25103==    by 0x112E11: thread_monitor (monitor.c:142)
==25103==    by 0x6CCDFA2: start_thread (pthread_create.c:486)
==25103==    by 0x6FBD4CE: clone (clone.S:95)
==25103==
==25103== LEAK SUMMARY:
==25103==    definitely lost: 88 bytes in 1 blocks
==25103==    indirectly lost: 96 bytes in 2 blocks
==25103==      possibly lost: 0 bytes in 0 blocks
==25103==    still reachable: 105,417 bytes in 675 blocks
==25103==         suppressed: 2,897 bytes in 107 blocks
==25103== Reachable blocks (those to which a pointer was found) are not shown.
==25103== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==25103==
==25103== For counts of detected and suppressed errors, rerun with: -v
==25103== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

And the modified function:

/*
 * New function to read integer from
 * ini file using GLIB
 */
int ini_getInteger(char *ini_file, char *section, char *key, int def_value) {

    g_autoptr(GError) error = NULL;
    g_autoptr(GKeyFile) localini = g_key_file_new ();

    //GKeyFile *localini = NULL;
    //GError *error = NULL;
    
    int abc = 0;
    //localini = g_key_file_new();

    if (g_key_file_load_from_file(localini, ini_file, G_KEY_FILE_KEEP_COMMENTS, &error) == FALSE) {
        mylog_log("Error loading ini file.\n");
        //g_key_file_free(localini);
        if (error != NULL) {            
            //g_error_free(error);
            mylog_log_level(0,"Error no ini.\n");
        }

        return def_value;
    }

    
    abc = g_key_file_get_integer(localini, section, key, &error);
    //g_key_file_free(localini);
    
    if (error != NULL) {
        if (error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND || error->code == G_KEY_FILE_ERROR_INVALID_VALUE || error->code == G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            //g_error_free(error);
            mylog_log_level(0,"Error no ini2 Section: '%s', Key: '%s', error: '%s'.\n", section, key, error->message);
            return def_value;
        } else {
            //g_error_free(error);
            mylog_log_level(0,"Error no ini3.\n");
            return abc;
        }
    } else {
        return abc;
    }
    

}

Try replacing match-leak-kinds:reachable with match-leak-kinds:reachable,definite and see if that helps. Let me know if so.

Tks!
Worked! Got no more ‘definitely loss’, but still getting some indirect loss. I have tried to modify supp file (adding the indirect loss function), but didn’t worked. Any tips?

==29246== 64 bytes in 1 blocks are indirectly lost in loss record 45 of 61
==29246==    at 0x6CA9B65: calloc (vg_replace_malloc.c:752)
==29246==    by 0x6D4A918: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==29246==    by 0x6D32821: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==29246==    by 0x6D33937: g_hash_table_remove_all (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5800.3)
==29246==    by 0x6CCD1A0: __nptl_deallocate_tsd.part.8 (pthread_create.c:301)
==29246==    by 0x6CCDFC3: __nptl_deallocate_tsd (pthread_create.c:256)
==29246==    by 0x6CCDFC3: start_thread (pthread_create.c:497)
==29246==    by 0x6FBD4CE: clone (clone.S:95)

That I have added to .supp file:

{
        g-hash-table_remove_all-malloc
        Memcheck:Leak
        match-leak-kinds:reachable,definite
        fun:malloc
        ...
        fun:g_hash_table_remove_all
}

{
        g-hash-table_remove_all-calloc
        Memcheck:Leak
        match-leak-kinds:reachable,definite
        fun:calloc
        ...
        fun:g_hash_table_remove_all
}

{
        g-hash-table_remove_all-realloc
        Memcheck:Leak
        match-leak-kinds:reachable,definite
        fun:realloc
        ...
        fun:g_hash_table_remove_all
}

You need to install debug symbols for GLib in order for the new backtrace from valgrind to be useful.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.