I’ve found this astuce while browsing minishell channel on discord.
We know the functions from the readline library have leaks and we can’t do anything about this. It is annoying to check valgrind and distinguish which are our own leaks and which are the system ones, so the trick is to tell valgrind, ignore leaks that come from this location:
{
ignore_libreadline_leaks
Memcheck:Leak
...
obj:*/libreadline.so.*
}
you put this code in a your_file_name.supp file next to your executable and you launch it with this command:
valgrind --suppressions=valgrind_readline_leaks_ignore.supp --leak-check=full ./your_exec
I have tried to make this as a makefile rule :
it works, but maybe this is not the most optimal way of handling this, I need to think about it.
still wip, if something does not work as intended I will correct when I encounter the issue. Currently, only the tests rule is functional since we don't have a main.c yet, skip to the second test directly if you’re working on integration or unit test.
From project root (this is for the final program, not the tests) :
*# Run valgrind on the main minishell program*
make valgrind
So basically, you just type this and it does everything for you. It will create the .supp file automatically if it's not there, then launch valgrind with all the right flags.
From tests/ directory (use only this for now while testing):
*# Run valgrind on a specific test*
make valgrind TEST=unit/test_core_process_line.c
make valgrind TEST=integration/test_core_shell_loop.c
Same but for tests. It will even compile the test first if you haven't built it yet.