diff options
author | Amar Tumballi <amarts@redhat.com> | 2018-11-25 11:01:01 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-11-28 03:29:32 +0000 |
commit | bbf1b9090b6b51292afab4af4479ef2d4ca61265 (patch) | |
tree | abf893678ea472e53ef180515a7c00b479c68a9e | |
parent | 6d69a663497ba2bb90b42eae8384cc57d6e4b283 (diff) |
posix: fix memory leak
Direct leak of 609960 byte(s) in 4485 object(s) allocated from:
#0 0x7f0d719bea50 in __interceptor_calloc (/lib64/libasan.so.5+0xefa50)
#1 0x7f0d716dc08f in __gf_calloc ../../../libglusterfs/src/mem-pool.c:111
#2 0x7f0d5d41d9b2 in __posix_get_mdata_xattr ../../../../../xlators/storage/posix/src/posix-metadata.c:240
#3 0x7f0d5d41dd6b in posix_get_mdata_xattr ../../../../../xlators/storage/posix/src/posix-metadata.c:317
#4 0x7f0d5d39e855 in posix_fdstat ../../../../../xlators/storage/posix/src/posix-helpers.c:685
#5 0x7f0d5d3d65ec in posix_create ../../../../../xlators/storage/posix/src/posix-entry-ops.c:2173
Direct leak of 609960 byte(s) in 4485 object(s) allocated from:
#0 0x7f0d719bea50 in __interceptor_calloc (/lib64/libasan.so.5+0xefa50)
#1 0x7f0d716dc08f in __gf_calloc ../../../libglusterfs/src/mem-pool.c:111
#2 0x7f0d5d41ced2 in posix_set_mdata_xattr ../../../../../xlators/storage/posix/src/posix-metadata.c:359
#3 0x7f0d5d41e70f in posix_set_ctime ../../../../../xlators/storage/posix/src/posix-metadata.c:616
#4 0x7f0d5d3d662c in posix_create ../../../../../xlators/storage/posix/src/posix-entry-ops.c:2181
We were freeing only the first context in inode during forget, and not the second.
updates: bz#1633930
Change-Id: Ib61b4453aa3d2039d6ce660f52ef45390539b9db
Signed-off-by: Amar Tumballi <amarts@redhat.com>
-rw-r--r-- | xlators/storage/posix/src/posix-inode-fd-ops.c | 23 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-metadata.c | 7 |
2 files changed, 23 insertions, 7 deletions
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c index 8906584684d..651569bf041 100644 --- a/xlators/storage/posix/src/posix-inode-fd-ops.c +++ b/xlators/storage/posix/src/posix-inode-fd-ops.c @@ -5423,19 +5423,21 @@ posix_forget(xlator_t *this, inode_t *inode) { int ret = 0; char *unlink_path = NULL; - uint64_t ctx_uint = 0; + uint64_t ctx_uint1 = 0; + uint64_t ctx_uint2 = 0; posix_inode_ctx_t *ctx = NULL; + posix_mdata_t *mdata = NULL; struct posix_private *priv_posix = NULL; priv_posix = (struct posix_private *)this->private; if (!priv_posix) return 0; - ret = inode_ctx_del(inode, this, &ctx_uint); - if (!ctx_uint) - return 0; + ret = inode_ctx_del2(inode, this, &ctx_uint1, &ctx_uint2); + if (!ctx_uint1) + goto check_ctx2; - ctx = (posix_inode_ctx_t *)(uintptr_t)ctx_uint; + ctx = (posix_inode_ctx_t *)(uintptr_t)ctx_uint1; if (ctx->unlink_flag == GF_UNLINK_TRUE) { POSIX_GET_FILE_UNLINK_PATH(priv_posix->base_path, inode->gfid, @@ -5444,14 +5446,21 @@ posix_forget(xlator_t *this, inode_t *inode) gf_msg(this->name, GF_LOG_ERROR, ENOMEM, P_MSG_UNLINK_FAILED, "Failed to remove gfid :%s", uuid_utoa(inode->gfid)); ret = -1; - goto out; + goto ctx_free; } ret = sys_unlink(unlink_path); } -out: +ctx_free: pthread_mutex_destroy(&ctx->xattrop_lock); pthread_mutex_destroy(&ctx->write_atomic_lock); pthread_mutex_destroy(&ctx->pgfid_lock); GF_FREE(ctx); + +check_ctx2: + if (ctx_uint2) { + mdata = (posix_mdata_t *)(uintptr_t)ctx_uint2; + } + + GF_FREE(mdata); return ret; } diff --git a/xlators/storage/posix/src/posix-metadata.c b/xlators/storage/posix/src/posix-metadata.c index 62fc328dd3b..99b49ff4458 100644 --- a/xlators/storage/posix/src/posix-metadata.c +++ b/xlators/storage/posix/src/posix-metadata.c @@ -269,6 +269,7 @@ __posix_get_mdata_xattr(xlator_t *this, const char *real_path, int _fd, */ if (stbuf && op_errno != ENOENT) { ret = 0; + GF_FREE(mdata); goto out; } else { /* This case should not be hit. If it hits, @@ -342,6 +343,7 @@ posix_set_mdata_xattr(xlator_t *this, const char *real_path, int fd, posix_mdata_t *mdata = NULL; int ret = -1; int op_errno = 0; + bool free_mdata = false; GF_VALIDATE_OR_GOTO("posix", this, out); GF_VALIDATE_OR_GOTO(this->name, inode, out); @@ -412,6 +414,8 @@ posix_set_mdata_xattr(xlator_t *this, const char *real_path, int fd, mdata->mtime.tv_nsec = time->tv_nsec; __inode_ctx_set1(inode, this, (uint64_t *)&mdata); + } else { + free_mdata = true; } } @@ -485,6 +489,9 @@ out: stbuf->ia_atime_nsec = mdata->atime.tv_nsec; } + if (free_mdata) + GF_FREE(mdata); + return ret; } |