added ssl_free() to cleanup per-connection contexts
authorDaniel Kouřil <kouril@ics.muni.cz>
Tue, 17 Jan 2012 20:11:47 +0000 (20:11 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Tue, 17 Jan 2012 20:11:47 +0000 (20:11 +0000)
emi.canl.canl-c/src/canl.c
emi.canl.canl-c/src/canl_locl.h
emi.canl.canl-c/src/canl_ssl.c

index cd08f39..96f203c 100644 (file)
@@ -72,6 +72,7 @@ static int init_io_content(glb_ctx *cc, io_handler *io)
     if (!io->s_ctx)
         return set_error(cc, ENOMEM, posix_error, "Not enough memory");
 
+    io->authn_mech.type = AUTH_UNDEF;
     io->sock = -1;
     return 0;
 }
@@ -283,13 +284,14 @@ static void io_destroy(glb_ctx *cc, io_handler *io)
     io_handler *io_cc = (io_handler*) io;
 
     if (io_cc->s_ctx) {
-        if (io_cc->s_ctx->ssl_io) {
-            SSL_free(io_cc->s_ctx->ssl_io);
-            io_cc->s_ctx->ssl_io = NULL;
-        }
+       if (io_cc->s_ctx->ssl_io)
+           ssl_free(cc, io_cc->s_ctx->ssl_io);
+
+       free (io_cc->s_ctx);
+       io_cc->s_ctx = NULL;
     }
-    free (io_cc->s_ctx);
-    io_cc->s_ctx = NULL;
+
+    return;
 }
 
 
index 090f5be..8d94bb0 100644 (file)
@@ -49,6 +49,7 @@ typedef enum _CANL_ERROR_ORIGIN
 
 typedef enum _CANL_AUTH_MECHANISM
 {
+    AUTH_UNDEF = -1,
     x509 = 0,
     KRB5 = 1, /* and others may be added*/
     TLS,
@@ -109,6 +110,9 @@ typedef struct canl_mech {
     canl_err_code (*server_init)
         (glb_ctx *, void *);
 
+    canl_err_code (*free_ctx)
+       (glb_ctx *, void *);
+
     canl_err_code (*connect)
         (glb_ctx *, void *, io_handler *, struct timeval *, const char *);
 
@@ -137,6 +141,7 @@ int asyn_getservbyname(int a_family, asyn_result *ares_result,char const *name,
         struct timeval *timeout);
 int ssl_client_init(glb_ctx *cc, io_handler *io);
 int ssl_server_init(glb_ctx *cc);
+int ssl_free(glb_ctx *cc, void *ctx);
 int ssl_connect(glb_ctx *cc, io_handler *io, struct timeval *timeout, const char * host);
 int ssl_accept(glb_ctx *cc, io_handler *io,
         struct timeval *timeout);
index ea21047..ca68d55 100644 (file)
@@ -749,6 +749,13 @@ int ssl_close(glb_ctx *cc, io_handler *io)
     }
 }
 
+int
+ssl_free(glb_ctx *cc, void *ctx)
+{
+    SSL_free(ctx);
+    return 0;
+}
+
 canl_err_code 
 canl_ctx_set_ssl_cred(canl_ctx cc, char *cert, char *key,
         canl_password_callback cb, void *userdata)
@@ -815,6 +822,7 @@ struct canl_mech canl_mech_ssl = {
     ssl_initialize,
     ssl_client_init,
     ssl_server_init,
+    ssl_free,
     ssl_connect,
     ssl_accept,
     ssl_close,