Fixed resource and memory leak.

Fixed the following issues: log_location remained unclosed and memory
allocated for fullpath has never been freed.