summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-10-07 03:39:45 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-10-07 02:36:16 -0700
commite2b1e7bb775b2f2f95357550bac786961ec9848a (patch)
tree3d3768d909e1a5117b814bf86a1f454cc6614885 /xlators
parent65c68a0e9ae3d504bde99a81744c1b1103480430 (diff)
performance/stat-prefetch: fix memory leaks
- sp_cache_get_inode uses fd_lookup which internally increases the refcount of fd by 1. This needs to be unrefed once we get the cache. - for directories, stat is stored in the inode context in sp_lookup_cbk. but, while doing so, no check was being done for the presence of context in inode, resulting in leak of memory equal to sizeof (struct stat) when multiple lookups happened on the directory. stat was needed to serve the postparent member during lookup. postparent stat is needed only in releases having NFS related changes and hence removing code present to get postparent. - path constructed in sp_readdir was not freed. Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 257 (Backport stat-prefetch to 2.0) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=257
Diffstat (limited to 'xlators')
-rw-r--r--xlators/performance/stat-prefetch/src/stat-prefetch.c71
1 files changed, 14 insertions, 57 deletions
diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c
index 57bed9a52..4359c6449 100644
--- a/xlators/performance/stat-prefetch/src/stat-prefetch.c
+++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c
@@ -263,6 +263,8 @@ sp_get_cache_inode (xlator_t *this, inode_t *inode, int32_t pid)
}
cache = sp_get_cache_fd (this, fd);
+
+ fd_unref (fd);
out:
return cache;
}
@@ -364,35 +366,6 @@ sp_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, inode_t *inode,
struct stat *buf, dict_t *dict)
{
- struct stat *stbuf = NULL;
- int32_t ret = -1;
-
- if (op_ret == -1) {
- goto out;
- }
-
- if (S_ISDIR (buf->st_mode)) {
- stbuf = CALLOC (1, sizeof (*stbuf));
- if (stbuf == NULL) {
- op_ret = -1;
- op_errno = ENOMEM;
- gf_log (this->name, GF_LOG_ERROR, "out of memory");
- goto out;
- }
-
- memcpy (stbuf, buf, sizeof (*stbuf));
- ret = inode_ctx_put (inode, this, (long)stbuf);
- if (ret == -1) {
- op_ret = -1;
-
- /* FIXME: EINVAL is not correct */
- op_errno = EINVAL;
- FREE (stbuf);
- goto out;
- }
- }
-
-out:
SP_STACK_UNWIND (frame, op_ret, op_errno, inode, buf, dict);
return 0;
}
@@ -521,7 +494,6 @@ sp_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
int32_t ret = -1, op_ret = -1, op_errno = EINVAL;
sp_cache_t *cache = NULL;
struct stat *postparent = NULL, *buf = NULL;
- uint64_t value = 0;
call_frame_t *wind_frame = NULL;
char lookup_behind = 0;
@@ -538,18 +510,14 @@ sp_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
if (cache) {
ret = sp_cache_get_entry (cache, (char *)loc->name, &dirent);
if (ret == 0) {
- ret = inode_ctx_get (loc->parent, this, &value);
- if (ret == 0) {
- postparent = (void *)(long)value;
- buf = &dirent.d_stat;
- op_ret = 0;
- op_errno = 0;
- lookup_behind = 1;
- }
+ buf = &dirent.d_stat;
+ op_ret = 0;
+ op_errno = 0;
+ lookup_behind = 1;
}
}
-wind:
+wind:
if (lookup_behind) {
wind_frame = copy_frame (frame);
if (wind_frame == NULL) {
@@ -663,10 +631,17 @@ sp_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
STACK_WIND (frame, sp_readdir_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->readdir, fd, size, off);
+ if (path != NULL) {
+ FREE (path);
+ }
+
return 0;
unwind:
SP_STACK_UNWIND (frame, -1, errno, NULL);
+ if (path != NULL) {
+ FREE (path);
+ }
return 0;
}
@@ -1737,23 +1712,6 @@ unwind:
int32_t
-sp_forget (xlator_t *this, inode_t *inode)
-{
- struct stat *buf = NULL;
- uint64_t value = 0;
-
- inode_ctx_del (inode, this, &value);
-
- if (value) {
- buf = (void *)(long)value;
- FREE (buf);
- }
-
- return 0;
-}
-
-
-int32_t
sp_release (xlator_t *this, fd_t *fd)
{
sp_fd_ctx_t *fd_ctx = NULL;
@@ -1832,7 +1790,6 @@ struct xlator_mops mops = {
};
struct xlator_cbks cbks = {
- .forget = sp_forget,
.release = sp_release,
.releasedir = sp_release
};