Refactor the duplicated code to free SSL_CTX and SSL structures.

Add a helper function ssl_socket_free which does the job for us, saving
some lines of code.

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