Check that result is not nil before calling its deferred Close method