fix potential memory leak if connection fails