upcall: Resolve dict leak from up_(f)removexattr 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.

Solution: To avoid the leak up_(f)removexattr() now also does a
          dict_unref() on the newly created dict.

While reviewing the code in up_(f)setxattr() for a similar problem, it
was noticed that there is an extra dict created. There is no need for
this copy, upcall_local_init() can just take the dict that was passed as
argument to the FOP.

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>
This commit is contained in:
Mohit Agrawal 2017-01-13 12:17:05 +05:30 committed by Niels de Vos
parent 2041fb7872
commit afdd83a9b6

View File

@ -1682,22 +1682,14 @@ 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;
}
dict_unref (xattr);
out:
STACK_WIND (frame, up_setxattr_cbk, FIRST_CHILD(this),
@ -1707,8 +1699,6 @@ out:
return 0;
err:
if (xattr)
dict_unref (xattr);
UPCALL_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
return 0;
@ -1769,22 +1759,14 @@ 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;
}
dict_unref (xattr);
out:
STACK_WIND (frame, up_fsetxattr_cbk,
@ -1794,8 +1776,6 @@ out:
return 0;
err:
if (xattr)
dict_unref (xattr);
UPCALL_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL);
return 0;
@ -1872,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;
@ -1954,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;