Fix creation of shared_ptr to be exception safe and close logger file descriptor