diff options
author | dvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-09-24 20:38:31 +0000 |
---|---|---|
committer | dvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-09-24 20:38:31 +0000 |
commit | 19f8fd53bd6e67cbbbb53e02cd2512388884773a (patch) | |
tree | f1766cbedc0d89111a760ae8161ea58402b686bd /main | |
parent | 054584618c372491f8e7fddc83a7f00a4a1f5f78 (diff) |
Merged revisions 220365 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r220365 | dvossel | 2009-09-24 15:37:20 -0500 (Thu, 24 Sep 2009) | 8 lines
fixes tcptls_session memory leak caused by ref count error
(closes issue #15939)
Reported by: dvossel
Review: https://reviewboard.asterisk.org/r/375/
........
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@220371 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/tcptls.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/main/tcptls.c b/main/tcptls.c index 1d19bfed0..0a715286d 100644 --- a/main/tcptls.c +++ b/main/tcptls.c @@ -122,6 +122,8 @@ static void session_instance_destructor(void *obj) * 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 @@ static void *handle_tls_connection(void *data) if (peer) X509_free(peer); fclose(tcptls_session->f); + ao2_ref(tcptls_session, -1); return NULL; } } @@ -262,6 +265,7 @@ void *ast_tcptls_server_root(void *data) 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); @@ -391,8 +395,9 @@ struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_se __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; |