I'm trying to write unit tests for a C lib I've made.
To do so I'm using the lib criterion.
I would like to use valgrind to detect memory leaks and context error, when I run make test it generate a unit_test.o file that I can run throw valgrind and here is the result :
test: clean $(TEST_OBJ)
$(CC) -o ${TEST_NAME} ${SRC} $(TEST_SRC) --coverage -lcriterion
./${TEST_NAME}
As you can see, I have 0 leaks and 0 context error which is not true as the tested code contains both. If I run the same code in the main function It will detect both leaks and contexts.
It looks like criterion execute the unit_tests in a kind of "safe" context and free all the memory itself.
My question is how can I test leaks and contexts from my criterion unit tests ?
Or, what are the alternative to test it ?

You'll have to look at the documentation for Criterion — but the chances are high that the default mode launches tests in separate processes.
[…Time passeth…] The source code for the Snaipe/Criterion unit test framework is available on GitHub (at https://github.com/Snaipe/Criterion), and one of the features claimed on the home page is "Test [sic] are isolated in their own process, crashes and signals can be reported and tested".
However, Valgrind has options to help, notably:
--trace-children=no|yesValgrind-ise child processes (follow execve)? [no].--trace-children-skip=patt1,patt2,...specifies a list of executables that--trace-children=yesshould not trace into.--trace-children-skip-by-arg=patt1,patt2,...same as--trace-children-skip=but check theargv[]entries for children, rather than the exe name, to make a follow/no-follow decision.Setting
--trace-children=yesas an option to Valgrind should help you.