daemon: Fix possible leak and unclear/undefined free behavior

Some versions of gcc complain about this code, as it's using the
cleanup attribute in a loop. Make the code clearer and defined.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>