cb8e9e
From 732680245cf72caa23b3f66da0960920d5c7027e Mon Sep 17 00:00:00 2001
cb8e9e
From: vmallika <vmallika@redhat.com>
cb8e9e
Date: Sun, 12 Jul 2015 21:03:54 +0530
cb8e9e
Subject: [PATCH 239/244] quota/marker: fix mem-leak in marker
cb8e9e
cb8e9e
This is a backport of http://review.gluster.org/#/c/11617/
cb8e9e
cb8e9e
Free local in error paths
cb8e9e
cb8e9e
> Change-Id: I76f69e7d746af8eedea34354ff5a6bf50234e50e
cb8e9e
> BUG: 1207735
cb8e9e
> Signed-off-by: vmallika <vmallika@redhat.com>
cb8e9e
cb8e9e
Change-Id: Ic2d3aefe2e090ecfad87747a90c7d95eff968d42
cb8e9e
BUG: 1224177
cb8e9e
Signed-off-by: vmallika <vmallika@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/52779
cb8e9e
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
cb8e9e
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
cb8e9e
---
cb8e9e
 xlators/features/marker/src/marker.c |   81 +++++++++++++--------------------
cb8e9e
 xlators/features/marker/src/marker.h |   12 +++++
cb8e9e
 2 files changed, 44 insertions(+), 49 deletions(-)
cb8e9e
cb8e9e
diff --git a/xlators/features/marker/src/marker.c b/xlators/features/marker/src/marker.c
cb8e9e
index db6943c..ba599da 100644
cb8e9e
--- a/xlators/features/marker/src/marker.c
cb8e9e
+++ b/xlators/features/marker/src/marker.c
cb8e9e
@@ -343,10 +343,6 @@ marker_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
cb8e9e
                      int32_t op_ret, int32_t op_errno, dict_t *dict,
cb8e9e
                      dict_t *xdata)
cb8e9e
 {
cb8e9e
-        marker_local_t *local = NULL;
cb8e9e
-        local = frame->local;
cb8e9e
-
cb8e9e
-
cb8e9e
         if (cookie) {
cb8e9e
                 gf_log (this->name, GF_LOG_DEBUG,
cb8e9e
                         "Filtering the quota extended attributes");
cb8e9e
@@ -372,9 +368,7 @@ marker_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
cb8e9e
                 marker_filter_internal_xattrs (frame->this, dict);
cb8e9e
         }
cb8e9e
 
cb8e9e
-        frame->local = NULL;
cb8e9e
-        STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata);
cb8e9e
-        marker_local_unref (local);
cb8e9e
+        MARKER_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, xdata);
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -422,9 +416,7 @@ marker_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 out:
cb8e9e
-        frame->local = NULL;
cb8e9e
-        STACK_UNWIND_STRICT (getxattr, frame, -1, ENOMEM, NULL, NULL);
cb8e9e
-        marker_local_unref (local);
cb8e9e
+        MARKER_STACK_UNWIND (getxattr, frame, -1, ENOMEM, NULL, NULL);
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -661,8 +653,9 @@ wind:
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (mkdir, frame, -1, ENOMEM, NULL,
cb8e9e
+        MARKER_STACK_UNWIND (mkdir, frame, -1, ENOMEM, NULL,
cb8e9e
                              NULL, NULL, NULL, NULL);
cb8e9e
+
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -735,7 +728,7 @@ wind:
cb8e9e
                     fd, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (create, frame, -1, ENOMEM, NULL, NULL, NULL, NULL,
cb8e9e
+        MARKER_STACK_UNWIND (create, frame, -1, ENOMEM, NULL, NULL, NULL, NULL,
cb8e9e
                              NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
@@ -811,7 +804,7 @@ wind:
cb8e9e
                     flags, iobref, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (writev, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (writev, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -879,7 +872,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->rmdir, loc, flags, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (rmdir, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (rmdir, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -958,9 +951,7 @@ unlink_wind:
cb8e9e
                     FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        frame->local = NULL;
cb8e9e
-        STACK_UNWIND_STRICT (unlink, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
-        marker_local_unref (local);
cb8e9e
+        MARKER_STACK_UNWIND (unlink, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -1034,7 +1025,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (link, frame, -1, ENOMEM, NULL, NULL, NULL, NULL,
cb8e9e
+        MARKER_STACK_UNWIND (link, frame, -1, ENOMEM, NULL, NULL, NULL, NULL,
cb8e9e
                              NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
@@ -1616,8 +1607,9 @@ rename_wind:
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (rename, frame, -1, ENOMEM, NULL,
cb8e9e
+        MARKER_STACK_UNWIND (rename, frame, -1, ENOMEM, NULL,
cb8e9e
                              NULL, NULL, NULL, NULL, NULL);
cb8e9e
+        marker_local_unref (oplocal);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -1686,7 +1678,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (truncate, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (truncate, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -1754,7 +1746,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (ftruncate, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -1828,8 +1820,9 @@ wind:
cb8e9e
                     xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (symlink, frame, -1, ENOMEM, NULL,
cb8e9e
+        MARKER_STACK_UNWIND (symlink, frame, -1, ENOMEM, NULL,
cb8e9e
                              NULL, NULL, NULL, NULL);
cb8e9e
+
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -1904,8 +1897,9 @@ wind:
cb8e9e
                     xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (mknod, frame, -1, ENOMEM, NULL,
cb8e9e
+        MARKER_STACK_UNWIND (mknod, frame, -1, ENOMEM, NULL,
cb8e9e
                              NULL, NULL, NULL, NULL);
cb8e9e
+
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -1973,7 +1967,7 @@ wind:
cb8e9e
 		    xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (fallocate, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (fallocate, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2041,7 +2035,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->discard, fd, offset, len, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (discard, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (discard, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2108,7 +2102,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->zerofill, fd, offset, len, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (zerofill, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (zerofill, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2229,16 +2223,11 @@ quota_xattr_cleaner_cbk (int ret, call_frame_t *frame, void *args)
cb8e9e
         dict_t *xdata = args;
cb8e9e
         int op_ret = -1;
cb8e9e
         int op_errno = 0;
cb8e9e
-	marker_local_t *local = NULL;
cb8e9e
-
cb8e9e
-	local = frame->local;
cb8e9e
-	frame->local = NULL;
cb8e9e
 
cb8e9e
         op_ret   = (ret < 0)? -1: 0;
cb8e9e
         op_errno = -ret;
cb8e9e
 
cb8e9e
-        STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata);
cb8e9e
-	marker_local_unref (local);
cb8e9e
+        MARKER_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata);
cb8e9e
         return ret;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -2312,11 +2301,9 @@ marker_do_xattr_cleanup (call_frame_t *frame, xlator_t *this, dict_t *xdata,
cb8e9e
 
cb8e9e
         ret = 0;
cb8e9e
 out:
cb8e9e
-        if (ret) {
cb8e9e
-		frame->local = NULL;
cb8e9e
-                STACK_UNWIND_STRICT (setxattr, frame, -1, ENOMEM, xdata);
cb8e9e
-		marker_local_unref (local);
cb8e9e
-        }
cb8e9e
+        if (ret)
cb8e9e
+                MARKER_STACK_UNWIND (setxattr, frame, -1, ENOMEM, xdata);
cb8e9e
+
cb8e9e
         return ret;
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -2371,7 +2358,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2438,7 +2425,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (fsetxattr, frame, -1, ENOMEM, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (fsetxattr, frame, -1, ENOMEM, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2504,7 +2491,7 @@ wind:
cb8e9e
                     FIRST_CHILD (this)->fops->fsetattr, fd, stbuf, valid, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (fsetattr, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (fsetattr, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2571,7 +2558,7 @@ wind:
cb8e9e
                     FIRST_CHILD (this)->fops->setattr, loc, stbuf, valid, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (setattr, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (setattr, frame, -1, ENOMEM, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2636,7 +2623,7 @@ wind:
cb8e9e
                     FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (removexattr, frame, -1, ENOMEM, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (removexattr, frame, -1, ENOMEM, NULL);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2746,7 +2733,7 @@ wind:
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 err:
cb8e9e
-        STACK_UNWIND_STRICT (lookup, frame, -1, ENOMEM, NULL, NULL, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (lookup, frame, -1, ENOMEM, NULL, NULL, NULL, NULL);
cb8e9e
 
cb8e9e
         if (xattr_req)
cb8e9e
                 dict_unref (xattr_req);
cb8e9e
@@ -2858,11 +2845,7 @@ marker_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
cb8e9e
         }
cb8e9e
 
cb8e9e
 unwind:
cb8e9e
-        local = frame->local;
cb8e9e
-        frame->local = NULL;
cb8e9e
-
cb8e9e
-        STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries, xdata);
cb8e9e
-        marker_local_unref (local);
cb8e9e
+        MARKER_STACK_UNWIND (readdirp, frame, op_ret, op_errno, entries, xdata);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -2906,7 +2889,7 @@ marker_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
cb8e9e
         dict_unref (dict);
cb8e9e
         return 0;
cb8e9e
 unwind:
cb8e9e
-        STACK_UNWIND_STRICT (readdirp, frame, -1, ENOMEM, NULL, NULL);
cb8e9e
+        MARKER_STACK_UNWIND (readdirp, frame, -1, ENOMEM, NULL, NULL);
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
diff --git a/xlators/features/marker/src/marker.h b/xlators/features/marker/src/marker.h
cb8e9e
index aadd877..f198859 100644
cb8e9e
--- a/xlators/features/marker/src/marker.h
cb8e9e
+++ b/xlators/features/marker/src/marker.h
cb8e9e
@@ -80,6 +80,18 @@ enum {
cb8e9e
                 frame->cookie = NULL;                           \
cb8e9e
         } while (0)
cb8e9e
 
cb8e9e
+#define MARKER_STACK_UNWIND(fop, frame, params...)              \
cb8e9e
+        do {                                                    \
cb8e9e
+                quota_local_t *_local = NULL;                   \
cb8e9e
+                if (frame) {                                    \
cb8e9e
+                        _local = frame->local;                  \
cb8e9e
+                        frame->local = NULL;                    \
cb8e9e
+                }                                               \
cb8e9e
+                STACK_UNWIND_STRICT (fop, frame, params);       \
cb8e9e
+                if (_local)                                     \
cb8e9e
+                        marker_local_unref (_local);            \
cb8e9e
+        } while (0)
cb8e9e
+
cb8e9e
 struct marker_local{
cb8e9e
         uint32_t        timebuf[2];
cb8e9e
         pid_t           pid;
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e