summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Hernandez <xhernandez@datalab.es>2017-03-09 09:29:49 +0100
committerShyamsundar Ranganathan <srangana@redhat.com>2017-03-15 21:38:59 -0400
commit1c5277d1d1ad55dfbabbd6c5bf6078e0d4b6b118 (patch)
treea6ec040083d95cfe001dcffdde8c4176e0bac785
parent43de8105010b2200138a724bfef829809dc9f0ed (diff)
features/locks: Fix leak of posix_lock_t's client_uid
> Change-Id: I3bc14998ed6a8841f77a004c24a456331048a521 > BUG: 1428510 > Signed-off-by: Xavier Hernandez <xhernandez@datalab.es> > Reviewed-on: https://review.gluster.org/16838 > Smoke: Gluster Build System <jenkins@build.gluster.org> > NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> > CentOS-regression: Gluster Build System <jenkins@build.gluster.org> > Reviewed-by: Amar Tumballi <amarts@gmail.com> > Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Change-Id: I3bc14998ed6a8841f77a004c24a456331048a521 BUG: 1431591 Signed-off-by: Xavier Hernandez <xhernandez@datalab.es> Reviewed-on: https://review.gluster.org/16895 Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
-rw-r--r--xlators/features/locks/src/common.c92
-rw-r--r--xlators/features/locks/src/posix.c6
-rw-r--r--xlators/features/locks/src/reservelk.c18
3 files changed, 47 insertions, 69 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
index 796b538f6f2..bd479ea439a 100644
--- a/xlators/features/locks/src/common.c
+++ b/xlators/features/locks/src/common.c
@@ -433,7 +433,7 @@ pl_inode_get (xlator_t *this, inode_t *inode)
INIT_LIST_HEAD (&pl_inode->blocked_reservelks);
INIT_LIST_HEAD (&pl_inode->blocked_calls);
INIT_LIST_HEAD (&pl_inode->metalk_list);
- INIT_LIST_HEAD (&pl_inode->queued_locks);
+ INIT_LIST_HEAD (&pl_inode->queued_locks);
gf_uuid_copy (pl_inode->gfid, inode->gfid);
ret = __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode));
@@ -510,9 +510,27 @@ __delete_lock (posix_lock_t *lock)
void
__destroy_lock (posix_lock_t *lock)
{
+ GF_FREE (lock->client_uid);
GF_FREE (lock);
}
+static posix_lock_t *
+__copy_lock(posix_lock_t *src)
+{
+ posix_lock_t *dst;
+
+ dst = GF_CALLOC(1, sizeof(posix_lock_t), gf_locks_mt_posix_lock_t);
+ if (dst != NULL) {
+ memcpy (dst, src, sizeof(posix_lock_t));
+ dst->client_uid = gf_strdup(src->client_uid);
+ if (dst->client_uid == NULL) {
+ GF_FREE(dst);
+ dst = NULL;
+ }
+ }
+
+ return dst;
+}
/* Convert a posix_lock to a struct gf_flock */
void
@@ -618,11 +636,11 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)
if ((big->fl_start == small->fl_start) &&
(big->fl_end == small->fl_end)) {
/* both edges coincide with big */
- v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[0])
+ v.locks[0] = __copy_lock(big);
+ if (!v.locks[0]) {
goto out;
- memcpy (v.locks[0], big, sizeof (posix_lock_t));
+ }
+
v.locks[0]->fl_type = small->fl_type;
goto done;
}
@@ -630,27 +648,15 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)
if ((small->fl_start > big->fl_start) &&
(small->fl_end < big->fl_end)) {
/* both edges lie inside big */
- v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[0])
- goto out;
-
- v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[1])
- goto out;
-
- v.locks[2] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[1])
+ v.locks[0] = __copy_lock(big);
+ v.locks[1] = __copy_lock(small);
+ v.locks[2] = __copy_lock(big);
+ if ((v.locks[0] == NULL) || (v.locks[1] == NULL) ||
+ (v.locks[2] == NULL)) {
goto out;
+ }
- memcpy (v.locks[0], big, sizeof (posix_lock_t));
v.locks[0]->fl_end = small->fl_start - 1;
-
- memcpy (v.locks[1], small, sizeof (posix_lock_t));
-
- memcpy (v.locks[2], big, sizeof (posix_lock_t));
v.locks[2]->fl_start = small->fl_end + 1;
goto done;
@@ -658,38 +664,24 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)
/* one edge coincides with big */
if (small->fl_start == big->fl_start) {
- v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[0])
- goto out;
-
- v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[1])
+ v.locks[0] = __copy_lock(big);
+ v.locks[1] = __copy_lock(small);
+ if ((v.locks[0] == NULL) || (v.locks[1] == NULL)) {
goto out;
+ }
- memcpy (v.locks[0], big, sizeof (posix_lock_t));
v.locks[0]->fl_start = small->fl_end + 1;
-
- memcpy (v.locks[1], small, sizeof (posix_lock_t));
goto done;
}
if (small->fl_end == big->fl_end) {
- v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[0])
- goto out;
-
- v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!v.locks[1])
+ v.locks[0] = __copy_lock(big);
+ v.locks[1] = __copy_lock(small);
+ if ((v.locks[0] == NULL) || (v.locks[1] == NULL)) {
goto out;
+ }
- memcpy (v.locks[0], big, sizeof (posix_lock_t));
v.locks[0]->fl_end = small->fl_start - 1;
-
- memcpy (v.locks[1], small, sizeof (posix_lock_t));
goto done;
}
@@ -698,15 +690,15 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)
out:
if (v.locks[0]) {
- GF_FREE (v.locks[0]);
+ __destroy_lock(v.locks[0]);
v.locks[0] = NULL;
}
if (v.locks[1]) {
- GF_FREE (v.locks[1]);
+ __destroy_lock(v.locks[1]);
v.locks[1] = NULL;
}
if (v.locks[2]) {
- GF_FREE (v.locks[2]);
+ __destroy_lock(v.locks[2]);
v.locks[2] = NULL;
}
@@ -972,7 +964,7 @@ grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode)
STACK_UNWIND_STRICT (lk, lock->frame, 0, 0,
&lock->user_flock, NULL);
- GF_FREE (lock);
+ __destroy_lock(lock);
}
return;
@@ -1018,7 +1010,7 @@ pl_send_prelock_unlock (xlator_t *this, pl_inode_t *pl_inode,
STACK_UNWIND_STRICT (lk, lock->frame, 0, 0,
&lock->user_flock, NULL);
- GF_FREE (lock);
+ __destroy_lock(lock);
}
out:
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index 0e75ad889be..931b9aeb6c5 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -3064,8 +3064,7 @@ out:
STACK_UNWIND_STRICT (lk, posix_lock->frame, -1, EREMOTE,
&posix_lock->user_flock, NULL);
- GF_FREE (posix_lock->client_uid);
- GF_FREE (posix_lock);
+ __destroy_lock(posix_lock);
}
return ret;
@@ -3571,8 +3570,7 @@ unlock:
STACK_UNWIND_STRICT (lk, posix_lock->frame, -1, EREMOTE,
&posix_lock->user_flock, NULL);
- GF_FREE (posix_lock->client_uid);
- GF_FREE (posix_lock);
+ __destroy_lock(posix_lock);
}
return 0;
}
diff --git a/xlators/features/locks/src/reservelk.c b/xlators/features/locks/src/reservelk.c
index 8eb08d0ef79..13b23f9f887 100644
--- a/xlators/features/locks/src/reservelk.c
+++ b/xlators/features/locks/src/reservelk.c
@@ -18,18 +18,6 @@
#include "locks.h"
#include "common.h"
-void
-__delete_reserve_lock (posix_lock_t *lock)
-{
- list_del (&lock->list);
-}
-
-void
-__destroy_reserve_lock (posix_lock_t *lock)
-{
- GF_FREE (lock);
-}
-
/* Return true if the two reservelks have exactly same lock boundaries */
int
reservelks_equal (posix_lock_t *l1, posix_lock_t *l2)
@@ -110,7 +98,7 @@ __reservelk_conflict (xlator_t *this, pl_inode_t *pl_inode,
list_del_init (&conf->list);
gf_log (this->name, GF_LOG_TRACE,
"Removing the matching reservelk for setlk to progress");
- GF_FREE (conf);
+ __destroy_lock(conf);
ret = 0;
} else {
gf_log (this->name, GF_LOG_TRACE,
@@ -217,7 +205,7 @@ __reserve_unlock_lock (xlator_t *this, posix_lock_t *lock, pl_inode_t *pl_inode)
" Matching lock not found for unlock");
goto out;
}
- __delete_reserve_lock (conf);
+ __delete_lock(conf);
gf_log (this->name, GF_LOG_DEBUG,
" Matching lock found for unlock");
@@ -392,7 +380,7 @@ pl_reserve_unlock (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock)
gf_log (this->name, GF_LOG_TRACE,
"Reservelk Unlock successful");
- __destroy_reserve_lock (retlock);
+ __destroy_lock(retlock);
ret = 0;
}
out: