From 39930ec5f8094595962c5c1dd188849c03b2cbde Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Tue, 6 Dec 2011 10:55:05 +0000 Subject: [PATCH] close sockets properly --- emi.canl.canl-c/Makefile | 2 +- emi.canl.canl-c/src/canl.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/emi.canl.canl-c/Makefile b/emi.canl.canl-c/Makefile index 2ff8a06..df25e83 100644 --- a/emi.canl.canl-c/Makefile +++ b/emi.canl.canl-c/Makefile @@ -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 diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index d40f683..8c639da 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -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) { -- 1.8.2.3