From 719987d79cd609c4aae80eafea9023c8fe6c4ec9 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Tue, 13 Jul 2010 03:32:29 +0000 Subject: protocol/server: Fix memory leak when server authentication fails. Thanks to zls for the patch. Signed-off-by: Pranith Kumar K Signed-off-by: Anand V. Avati BUG: 1012 (Memory leak in server_connection_cleanup) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1012 --- xlators/protocol/server/src/server-helpers.c | 67 ++++++++++++++++++---------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index f627b6b53..7b99ded23 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -675,8 +675,20 @@ server_connection_cleanup (xlator_t *this, server_connection_t *conn) } pthread_mutex_unlock (&conn->lock); - if (do_cleanup && conn->bound_xl) - ret = do_connection_cleanup (this, conn, ltable, fdentries, fd_count); + if (do_cleanup) { + if (conn->bound_xl) { + ret = do_connection_cleanup (this, conn, ltable, fdentries, fd_count); + } else { + if (ltable){ + free(ltable); + ltable = NULL; + } + if (fdentries){ + free(fdentries); + fdentries = NULL; + } + } + } out: return ret; @@ -705,6 +717,26 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) goto out; } + pthread_mutex_lock (&(conn->lock)); + { + if (conn->ltable) { + ltable = conn->ltable; + conn->ltable = NULL; + } + } + pthread_mutex_unlock (&conn->lock); + + pthread_mutex_lock (&(conn->lock)); + { + if (conn->fdtable) { + fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, + &fd_count); + gf_fd_fdtable_destroy (conn->fdtable); + conn->fdtable = NULL; + } + } + pthread_mutex_unlock (&conn->lock); + bound_xl = (xlator_t *) (conn->bound_xl); if (bound_xl) { @@ -713,15 +745,6 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) GF_EVENT_TRANSPORT_CLEANUP */ frame = create_frame (this, this->ctx->pool); - pthread_mutex_lock (&(conn->lock)); - { - if (conn->ltable) { - ltable = conn->ltable; - conn->ltable = NULL; - } - } - pthread_mutex_unlock (&conn->lock); - INIT_LIST_HEAD (&file_lockers); INIT_LIST_HEAD (&dir_lockers); @@ -802,17 +825,6 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) free (locker); } - pthread_mutex_lock (&(conn->lock)); - { - if (conn->fdtable) { - fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, - &fd_count); - gf_fd_fdtable_destroy (conn->fdtable); - conn->fdtable = NULL; - } - } - pthread_mutex_unlock (&conn->lock); - if (fdentries != NULL) { for (i = 0; i < fd_count; i++) { fd = fdentries[i].fd; @@ -829,7 +841,16 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) } FREE (fdentries); } - } + } else { + if (ltable){ + free(ltable); + ltable = NULL; + } + if (fdentries){ + free(fdentries); + fdentries = NULL; + } + } if (frame) { state = CALL_STATE (frame); -- cgit