diff options
author | Pranith Kumar K <pranithk@gluster.com> | 2010-07-13 03:32:29 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-07-13 22:12:05 -0700 |
commit | 719987d79cd609c4aae80eafea9023c8fe6c4ec9 (patch) | |
tree | 8f76208c2690425fcd227d9efbb70c787ecff41f /xlators | |
parent | 1ffcb93727955c96dc5c39a9bfaa047ad1d83a73 (diff) |
protocol/server: Fix memory leak when server authentication fails.
Thanks to zls <zls0424 at gmail dot com> for the patch.
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1012 (Memory leak in server_connection_cleanup)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1012
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/protocol/server/src/server-helpers.c | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index f627b6b530e..7b99ded2314 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); |