From c71110fb153adfd4628718f634348b7a5712bf32 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 16 Apr 2009 23:53:39 -0700 Subject: libglusterfsclient: Fix fd_ctx leak on release cbks Signed-off-by: Anand V. Avati --- libglusterfsclient/src/libglusterfsclient.c | 32 ++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 8d337e7d2..ee32cfe41 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -158,25 +158,47 @@ out: return fdctx; } +libglusterfs_client_fd_ctx_t * +libgf_del_fd_ctx (fd_t *fd) +{ + uint64_t ctxaddr = 0; + libglusterfs_client_fd_ctx_t *ctx = NULL; + + GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, fd, out); + + if (fd_ctx_del (fd, libgf_fd_to_xlator (fd) , &ctxaddr) == -1) + goto out; + + ctx = (libglusterfs_client_fd_ctx_t *)(long)ctxaddr; + +out: + return ctx; +} + int32_t libgf_client_release (xlator_t *this, fd_t *fd) { libglusterfs_client_fd_ctx_t *fd_ctx = NULL; - fd_ctx = libgf_get_fd_ctx (fd); - pthread_mutex_destroy (&fd_ctx->lock); + fd_ctx = libgf_del_fd_ctx (fd); + if (fd_ctx != NULL) { + pthread_mutex_destroy (&fd_ctx->lock); + FREE (fd_ctx); + } return 0; } - int32_t libgf_client_releasedir (xlator_t *this, fd_t *fd) { libglusterfs_client_fd_ctx_t *fd_ctx = NULL; - fd_ctx = libgf_get_fd_ctx (fd); - pthread_mutex_destroy (&fd_ctx->lock); + fd_ctx = libgf_del_fd_ctx (fd); + if (fd_ctx != NULL) { + pthread_mutex_destroy (&fd_ctx->lock); + FREE (fd_ctx); + } return 0; } -- cgit