Close logger and database on exit

zm binaries open a logger session but never close it and the same for the database access.
This results in memory leaks (not too offendous because this happens only on exit).