From dcf9f6fd363820f4e9b7b15bd6fb631e9fa3e049 Mon Sep 17 00:00:00 2001
From: Xavier Hernandez <jahernan@redhat.com>
Date: Mon, 20 Nov 2017 10:51:09 +0100
Subject: [PATCH 641/642] features/locks: Fix memory leaks
> Upstream patch: https://review.gluster.org/18812
Change-Id: Ic1d2e17a7d14389b6734d1b88bd28c0a2907bbd6
BUG: 1526377
Signed-off-by: Xavier Hernandez <jahernan@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/125954
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: RHGS Build Bot <nigelb@redhat.com>
---
xlators/features/locks/src/clear.c | 2 +-
xlators/features/locks/src/common.c | 8 +++++++-
xlators/features/locks/src/entrylk.c | 8 ++++----
xlators/features/locks/src/inodelk.c | 7 ++++---
xlators/features/locks/src/posix.c | 3 +++
5 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/xlators/features/locks/src/clear.c b/xlators/features/locks/src/clear.c
index 640c6bb..fc1a150 100644
--- a/xlators/features/locks/src/clear.c
+++ b/xlators/features/locks/src/clear.c
@@ -184,7 +184,7 @@ clrlk_clear_posixlk (xlator_t *this, pl_inode_t *pl_inode, clrlk_args *args,
} else {
gcount++;
}
- GF_FREE (plock);
+ __destroy_lock(plock);
}
}
pthread_mutex_unlock (&pl_inode->mutex);
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
index 015464c..b929786 100644
--- a/xlators/features/locks/src/common.c
+++ b/xlators/features/locks/src/common.c
@@ -436,7 +436,13 @@ pl_inode_get (xlator_t *this, inode_t *inode)
INIT_LIST_HEAD (&pl_inode->queued_locks);
gf_uuid_copy (pl_inode->gfid, inode->gfid);
- __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode));
+ ret = __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode));
+ if (ret) {
+ pthread_mutex_destroy (&pl_inode->mutex);
+ GF_FREE (pl_inode);
+ pl_inode = NULL;
+ goto unlock;
+ }
}
unlock:
UNLOCK (&inode->lock);
diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c
index 783c57e..8cd6f85 100644
--- a/xlators/features/locks/src/entrylk.c
+++ b/xlators/features/locks/src/entrylk.c
@@ -672,15 +672,12 @@ pl_common_entrylk (call_frame_t *frame, xlator_t *this,
break;
default:
- inode_unref (pinode->inode);
+ need_inode_unref = _gf_true;
gf_log (this->name, GF_LOG_ERROR,
"Unexpected case in entrylk (cmd=%d). Please file"
"a bug report at http://bugs.gluster.com", cmd);
goto out;
}
- if (need_inode_unref)
- inode_unref (pinode->inode);
-
/* The following (extra) unref corresponds to the ref that
* was done at the time the lock was granted.
*/
@@ -688,6 +685,8 @@ pl_common_entrylk (call_frame_t *frame, xlator_t *this,
inode_unref (pinode->inode);
out:
+ if (need_inode_unref)
+ inode_unref (pinode->inode);
if (unwind) {
entrylk_trace_out (this, frame, volume, fd, loc, basename,
@@ -848,6 +847,7 @@ pl_entrylk_client_cleanup (xlator_t *this, pl_ctx_t *ctx)
__pl_entrylk_unref (l);
}
pthread_mutex_unlock (&pinode->mutex);
+
inode_unref (pinode->inode);
}
diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c
index 1564f26..f0aa766 100644
--- a/xlators/features/locks/src/inodelk.c
+++ b/xlators/features/locks/src/inodelk.c
@@ -600,9 +600,6 @@ out:
if (ctx)
pthread_mutex_unlock (&ctx->lock);
- if (need_inode_unref)
- inode_unref (pl_inode->inode);
-
/* The following (extra) unref corresponds to the ref that
* was done at the time the lock was granted.
*/
@@ -611,6 +608,10 @@ out:
grant_blocked_inode_locks (this, pl_inode, dom);
}
+ if (need_inode_unref) {
+ inode_unref (pl_inode->inode);
+ }
+
return ret;
}
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index feca2f1..932831a 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -2482,6 +2482,7 @@ pl_forget (xlator_t *this,
list) {
list_del (&rw_req->list);
+ call_stub_destroy(rw_req->stub);
GF_FREE (rw_req);
}
}
@@ -2565,6 +2566,8 @@ pl_forget (xlator_t *this,
}
+ pthread_mutex_destroy(&pl_inode->mutex);
+
GF_FREE (pl_inode);
return 0;
--
2.9.3