return null pointer and deallocate memory when file not found