diff options
author | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-06-17 21:57:15 +0000 |
---|---|---|
committer | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-06-17 21:57:15 +0000 |
commit | 2ea4a890faabc5471bc32599f53a195884eb8260 (patch) | |
tree | 544d752de5985a5e0a2c542a5c4bbece5ce84d42 /main | |
parent | fb2783a6c52ccf189925ca6045468f5786a8d208 (diff) |
Merged revisions 123546 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r123546 | bbryant | 2008-06-17 16:46:57 -0500 (Tue, 17 Jun 2008) | 5 lines
Updates all usages of ast_tcptls_session_instance to be managed by reference counts so that they only get destroyed when all threads are done using
them, and memory does not get free'd causing strange issues with SIP.
This code was originally written by russellb in the team/group/issue_11972/ branch.
........
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@123547 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/http.c | 3 | ||||
-rw-r--r-- | main/manager.c | 3 | ||||
-rw-r--r-- | main/tcptls.c | 36 |
3 files changed, 31 insertions, 11 deletions
diff --git a/main/http.c b/main/http.c index 10eab25c3..7c1010f88 100644 --- a/main/http.c +++ b/main/http.c @@ -868,7 +868,8 @@ static void *httpd_helper_thread(void *data) done: fclose(ser->f); - ser = ast_tcptls_session_instance_destroy(ser); + ao2_ref(ser, -1); + ser = NULL; return NULL; } diff --git a/main/manager.c b/main/manager.c index 35c1fc83e..d655c5907 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2937,7 +2937,8 @@ static void *session_do(void *data) destroy_session(s); done: - ser = ast_tcptls_session_instance_destroy(ser); + ao2_ref(ser, -1); + ser = NULL; return NULL; } diff --git a/main/tcptls.c b/main/tcptls.c index 67782a08d..9ce3ac9b8 100644 --- a/main/tcptls.c +++ b/main/tcptls.c @@ -83,6 +83,12 @@ static int ssl_close(void *cookie) HOOK_T ast_tcptls_server_read(struct ast_tcptls_session_instance *ser, void *buf, size_t count) { + if (ser->fd == -1) { + ast_log(LOG_ERROR, "server_read called with an fd of -1\n"); + errno = EIO; + return -1; + } + #ifdef DO_SSL if (ser->ssl) return ssl_read(ser->ssl, buf, count); @@ -92,6 +98,12 @@ HOOK_T ast_tcptls_server_read(struct ast_tcptls_session_instance *ser, void *buf HOOK_T ast_tcptls_server_write(struct ast_tcptls_session_instance *ser, void *buf, size_t count) { + if (ser->fd == -1) { + ast_log(LOG_ERROR, "server_write called with an fd of -1\n"); + errno = EIO; + return -1; + } + #ifdef DO_SSL if (ser->ssl) return ssl_write(ser->ssl, buf, count); @@ -99,6 +111,12 @@ HOOK_T ast_tcptls_server_write(struct ast_tcptls_session_instance *ser, void *bu return write(ser->fd, buf, count); } +static void session_instance_destructor(void *obj) +{ + struct ast_tcptls_session_instance *i = obj; + ast_mutex_destroy(&i->lock); +} + void *ast_tcptls_server_root(void *data) { struct server_args *desc = data; @@ -123,12 +141,15 @@ void *ast_tcptls_server_root(void *data) ast_log(LOG_WARNING, "Accept failed: %s\n", strerror(errno)); continue; } - ser = ast_calloc(1, sizeof(*ser)); + ser = ao2_alloc(sizeof(*ser), session_instance_destructor); if (!ser) { ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno)); close(fd); continue; } + + ast_mutex_init(&ser->lock); + flags = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); ser->fd = fd; @@ -140,7 +161,7 @@ void *ast_tcptls_server_root(void *data) if (ast_pthread_create_detached_background(&launched, NULL, ast_make_file_from_fd, ser)) { ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno)); close(ser->fd); - ast_free(ser); + ao2_ref(ser, -1); } } return NULL; @@ -235,9 +256,11 @@ struct ast_tcptls_session_instance *ast_tcptls_client_start(struct server_args * goto error; } - if (!(ser = ast_calloc(1, sizeof(*ser)))) + if (!(ser = ao2_alloc(sizeof(*ser), session_instance_destructor))) goto error; + ast_mutex_init(&ser->lock); + flags = fcntl(desc->accept_fd, F_GETFL); fcntl(desc->accept_fd, F_SETFL, flags & ~O_NONBLOCK); @@ -262,7 +285,7 @@ error: close(desc->accept_fd); desc->accept_fd = -1; if (ser) - ast_free(ser); + ao2_ref(ser, -1); return NULL; } @@ -447,8 +470,3 @@ void *ast_make_file_from_fd(void *data) return ser; } -struct ast_tcptls_session_instance *ast_tcptls_session_instance_destroy(struct ast_tcptls_session_instance *i) -{ - ast_free(i); - return NULL; -} |