Reputation: 63
I am using a library called minilibx which is a wrapper to X11.
I changed the library by adding XInitThreads() to be initialisation function to use threading with the library (it will not work without this).
The program I compile is called fdf. When I check my program for leaks (valgrind --log-file=v.log --leak-check=full ./fdf test2.fdf
), Valgrind complains there is some allocation from XInitThreads, that has not been freed. Is there anything I can do to free this actively? Is there any function that I have to call at the end of the program to release allocation from XInitThreads?
Kind regards Bastian
My system (Ubuntu):
Linux 6.11.0-1-t2-jammy #1 SMP PREEMPT_DYNAMIC Tue Sep 17 06:47:39 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
v.log:
==1546656== Memcheck, a memory error detector
==1546656== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1546656== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==1546656== Command: ./fdf test2.fdf
==1546656== Parent PID: 1464122
==1546656==
==1546656==
==1546656== HEAP SUMMARY:
==1546656== in use at exit: 120 bytes in 3 blocks
==1546656== total heap usage: 53,837 allocs, 53,834 frees, 1,199,360 bytes allocated
==1546656==
==1546656== 40 bytes in 1 blocks are still reachable in loss record 1 of 3
==1546656== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1546656== by 0x48B09E9: XInitThreads (in /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0)
==1546656== by 0x11422A: mlx_init (in /home/baschnit/repos/42fdf_new/fdf)
==1546656== by 0x10AAB1: main (main.c:59)
==1546656==
==1546656== 40 bytes in 1 blocks are still reachable in loss record 2 of 3
==1546656== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1546656== by 0x48B0A06: XInitThreads (in /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0)
==1546656== by 0x11422A: mlx_init (in /home/baschnit/repos/42fdf_new/fdf)
==1546656== by 0x10AAB1: main (main.c:59)
==1546656==
==1546656== 40 bytes in 1 blocks are still reachable in loss record 3 of 3
==1546656== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1546656== by 0x48B0A23: XInitThreads (in /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0)
==1546656== by 0x11422A: mlx_init (in /home/baschnit/repos/42fdf_new/fdf)
==1546656== by 0x10AAB1: main (main.c:59)
==1546656==
==1546656== LEAK SUMMARY:
==1546656== definitely lost: 0 bytes in 0 blocks
==1546656== indirectly lost: 0 bytes in 0 blocks
==1546656== possibly lost: 0 bytes in 0 blocks
==1546656== still reachable: 120 bytes in 3 blocks
==1546656== suppressed: 0 bytes in 0 blocks
==1546656==
==1546656== For lists of detected and suppressed errors, rerun with: -s
==1546656== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1 from 1)
minimal reproducible example:
main.c:
#include <stdlib.h>
#include <X11/Xlib.h>
#include "mlx.h"
int main(void)
{
void *mlx;
XInitThreads();
mlx = mlx_init();
mlx_destroy_display(mlx);
free(mlx);
}
Upvotes: 2
Views: 92