Don't forget to close |sockfd| and free the ctx when necessary.

Release SSL_CTX in the error cases and also close the socket file
descriptor at those spots.

Spotted and suggested by Viet at:
https://github.com/dinhviethoa/gimap/commit/78c00d9459d766e9147d553f654b6671635a38e2

Signed-off-by: Thiago Farina <tfarina@chromium.org>