[asterisk-commits] dvossel: trunk r220365 - /trunk/main/tcptls.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 24 15:37:27 CDT 2009


Author: dvossel
Date: Thu Sep 24 15:37:20 2009
New Revision: 220365

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=220365
Log:
fixes tcptls_session memory leak caused by ref count error

(closes issue #15939)
Reported by: dvossel

Review: https://reviewboard.asterisk.org/r/375/


Modified:
    trunk/main/tcptls.c

Modified: trunk/main/tcptls.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/tcptls.c?view=diff&rev=220365&r1=220364&r2=220365
==============================================================================
--- trunk/main/tcptls.c (original)
+++ trunk/main/tcptls.c Thu Sep 24 15:37:20 2009
@@ -122,6 +122,8 @@
 * creates a FILE * from the fd passed by the accept thread.
 * This operation is potentially expensive (certificate verification),
 * so we do it in the child thread context.
+*
+* \note must decrement ref count before returning NULL on error
 */
 static void *handle_tls_connection(void *data)
 {
@@ -196,6 +198,7 @@
 						if (peer)
 							X509_free(peer);
 						fclose(tcptls_session->f);
+						ao2_ref(tcptls_session, -1);
 						return NULL;
 					}
 				}
@@ -262,6 +265,7 @@
 
 		tcptls_session->client = 0;
 
+		/* This thread is now the only place that controls the single ref to tcptls_session */
 		if (ast_pthread_create_detached_background(&launched, NULL, handle_tls_connection, tcptls_session)) {
 			ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
 			close(tcptls_session->fd);
@@ -418,8 +422,9 @@
 		__ssl_setup(desc->tls_cfg, 1);
 	}
 
-	ao2_ref(tcptls_session, +1);
-	if (!handle_tls_connection(tcptls_session))
+	/* handle_tls_connection controls the single ref to tcptls_session. If
+	 * tcptls_session returns NULL then the session has been destroyed */
+	if (!(tcptls_session = handle_tls_connection(tcptls_session)))
 		goto error;
 
 	return tcptls_session;




More information about the asterisk-commits mailing list