Fix: memory leak and logfile