From 45e94b687c3911dd70586a5a73e2d8493806f0ef Mon Sep 17 00:00:00 2001
From: moagrawa <moagrawa@redhat.com>
Date: Mon, 16 Jan 2017 15:15:23 +0530
Subject: [PATCH 271/275] upcall: Resolve dict leak from
up_(f)(remove|set)xattr in upcall code path
Problem: In up_(f)removexattr() dict_for_key_value() is used to create a
new dict . This dict is not correctly unref'd and gets leaked.
In up_(f)setxattr() dict leak is due to extra dict created after
call dict_copy_with_ref.
Solution: To avoid the leak in up_(f)removexattr() now also does a
dict_unref() on the newly created dict and to avoid the
leak in up_(f)setxattr() removed code to copy dict and
directly pass dict to upcall_local_init().
Note: The patch differs slightly from upstream because the code was updated
in upstream from the patch (http://review.gluster.org/#/c/13183/) but
the same patch was not merged in downstream.
> BUG: 1412917
> Change-Id: I5bb9a7d99f5087af11c19ae722de62bdb5ad1498
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
> Reviewed-on: http://review.gluster.org/16392
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Niels de Vos <ndevos@redhat.com>
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> (cherry picked from afdd83a9b69573b854e732795c0bcba0a00d6c0f)
BUG: 1411329
Change-Id: If8ab90209bf5f0f9c29284659401678985a99430
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/95350
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
xlators/features/upcall/src/upcall.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/xlators/features/upcall/src/upcall.c b/xlators/features/upcall/src/upcall.c
index ba5d118..19d9a9d 100644
--- a/xlators/features/upcall/src/upcall.c
+++ b/xlators/features/upcall/src/upcall.c
@@ -1682,17 +1682,10 @@ up_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
{
int32_t op_errno = -1;
upcall_local_t *local = NULL;
- dict_t *xattr = NULL;
EXIT_IF_UPCALL_OFF (this, out);
- xattr = dict_copy_with_ref (dict, NULL);
- if (!xattr) {
- op_errno = ENOMEM;
- goto err;
- }
-
- local = upcall_local_init (frame, this, loc, NULL, loc->inode, xattr);
+ local = upcall_local_init (frame, this, loc, NULL, loc->inode, dict);
if (!local) {
op_errno = ENOMEM;
goto err;
@@ -1766,17 +1759,10 @@ up_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
{
int32_t op_errno = -1;
upcall_local_t *local = NULL;
- dict_t *xattr = NULL;
EXIT_IF_UPCALL_OFF (this, out);
- xattr = dict_copy_with_ref (dict, NULL);
- if (!xattr) {
- op_errno = ENOMEM;
- goto err;
- }
-
- local = upcall_local_init (frame, this, NULL, fd, fd->inode, xattr);
+ local = upcall_local_init (frame, this, NULL, fd, fd->inode, dict);
if (!local) {
op_errno = ENOMEM;
goto err;
@@ -1866,12 +1852,18 @@ up_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
}
out:
+ if (xattr)
+ dict_unref (xattr);
+
STACK_WIND (frame, up_fremovexattr_cbk,
FIRST_CHILD(this), FIRST_CHILD(this)->fops->fremovexattr,
fd, name, xdata);
return 0;
err:
+ if (xattr)
+ dict_unref (xattr);
+
UPCALL_STACK_UNWIND (fremovexattr, frame, -1, op_errno, NULL);
return 0;
@@ -1948,12 +1940,18 @@ up_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
}
out:
+ if (xattr)
+ dict_unref (xattr);
+
STACK_WIND (frame, up_removexattr_cbk,
FIRST_CHILD(this), FIRST_CHILD(this)->fops->removexattr,
loc, name, xdata);
return 0;
err:
+ if (xattr)
+ dict_unref (xattr);
+
UPCALL_STACK_UNWIND (removexattr, frame, -1, op_errno, NULL);
return 0;
--
2.9.3