Fix fd leak in log handling.