Fixed idle db leaks by defer Close()'ing connections before returning due to error.