tests: Ensure the daemon exits with no error and fix leaks
We did terminate the daemon and waited for it, but we did not ensure that it was terminated with no error.
This is particularly a problem when we are running the sanitizers or valgrind, because we didn't catch any error.
Thus... We were living with some leaks that we never caught