Avoid leaking handles if a batch task gives an error.