close stderr when possible