I start to thinking that I’m really doing something wrong here
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;
}
}