Fix NULL pointer dereference while closing file pointer