close sockets properly
authorMarcel Poul <marcel.poul@cern.ch>
Tue, 6 Dec 2011 10:55:05 +0000 (10:55 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Tue, 6 Dec 2011 10:55:05 +0000 (10:55 +0000)
emi.canl.canl-c/Makefile
emi.canl.canl-c/src/canl.c

index 2ff8a06..df25e83 100644 (file)
@@ -16,7 +16,7 @@ COMPILE=libtool --mode=compile ${CC} ${CFLAGS}
 LINK=libtool --mode=link ${CC} ${LDFLAGS}
 INSTALL=libtool --mode=install install
 
-CFLAGS_LIB=-Wall -pedantic -fPIC -c -g -I${top_srcdir}/src ${LIBCARES_CFLAGS} ${LIBSSL_CFLAGS}
+CFLAGS_LIB=-Wall -pedantic -fPIC -c -g -I${top_srcdir}/src ${LIBCARES_CFLAGS} ${LIBSSL_CFLAGS} -DDEBUG
 LFLAGS_LIB=-shared ${LIBCARES_LIBS} ${LIBSSL_LIBS}
 
 CFLAGS_CLI=-Wall -g -I${top_srcdir}/src
index d40f683..8c639da 100644 (file)
@@ -316,8 +316,11 @@ int canl_io_accept(canl_ctx cc, canl_io_handler io, int port,
     err = ssl_accept(glb_cc, io_cc, (*io_new_cc), timeout); 
 
 end:
-    if (err)
+    if (err){
+        /* ssl_accept closed new_sock*/
+        (*io_new_cc)->sock = 0;
         update_error(glb_cc, "cannot accept connection (canl_io_accept)");
+    }
     return err;
 }
 
@@ -364,6 +367,10 @@ static void io_destroy(glb_ctx *cc, io_handler *io)
         free (io_cc->s_addr);
         io_cc->s_addr = NULL;
     }
+    if (io_cc->sock) {
+        fclose (io_cc->sock);
+        io_cc->sock = NULL;
+    }
     if (io_cc->s_ctx) {
         /*TODO maybe new function because of BIO_free and SSL_free*/
         if (io_cc->s_ctx->ssl_io) {