diff options
author | Xavier Hernandez <xhernandez@datalab.es> | 2017-03-09 09:29:49 +0100 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2017-03-11 19:52:12 -0500 |
commit | b3ac24cdd759fb4cd2946329860bcc004f736b23 (patch) | |
tree | a13a73470fedc5be257aca76f9ff6306096d5392 /xlators/features | |
parent | b9e1c911833ca1916055622e5265672d5935d925 (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>
Diffstat (limited to 'xlators/features')
-rw-r--r-- | xlators/features/locks/src/common.c | 92 | ||||
-rw-r--r-- | xlators/features/locks/src/posix.c | 6 | ||||
-rw-r--r-- | xlators/features/locks/src/reservelk.c | 18 |
3 files changed, 47 insertions, 69 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 68f253d92ad..95aa749fefe 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)); @@ -511,9 +511,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 @@ -619,11 +637,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; } @@ -631,27 +649,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; @@ -659,38 +665,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; } @@ -699,15 +691,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; } @@ -973,7 +965,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; @@ -1019,7 +1011,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 5d79fa16a66..44ca5004171 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -3065,8 +3065,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; @@ -3572,8 +3571,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: |