diff options
| author | Xavier Hernandez <xhernandez@datalab.es> | 2017-03-09 09:29:49 +0100 | 
|---|---|---|
| committer | Niels de Vos <ndevos@redhat.com> | 2017-04-07 07:54:42 -0400 | 
| commit | ca58ac814e2d983f6ebdf532a40ae9d5a216226b (patch) | |
| tree | 1c43f71616332ce0bb3ed259d4d68292299e84e6 | |
| parent | b787c17b4143ef81882529d9ffebcab5fb0748f0 (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: 1431592
Signed-off-by: Xavier Hernandez <xhernandez@datalab.es>
Reviewed-on: https://review.gluster.org/16896
Smoke: Gluster Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
| -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 d56a7aca2be..68904f63140 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);                  __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode)); @@ -505,9 +505,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 @@ -613,11 +631,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;          } @@ -625,27 +643,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; @@ -653,38 +659,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;          } @@ -693,15 +685,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;          } @@ -967,7 +959,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; @@ -1013,7 +1005,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 3415d59324c..f217220a04b 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -3077,8 +3077,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:  | 
