14f8ab
From 0d8c6d78130d22c475010bcce8055073b19de82a Mon Sep 17 00:00:00 2001
14f8ab
From: Xie Changlong <xiechanglong@cmss.chinamobile.com>
14f8ab
Date: Fri, 17 May 2019 18:33:11 +0800
14f8ab
Subject: [PATCH 358/362] inode: fix wrong loop count in __inode_ctx_free
14f8ab
14f8ab
Avoid serious memory leak
14f8ab
14f8ab
Backport of :
14f8ab
>fixes: bz#1711240
14f8ab
>Upstream patch link: https://review.gluster.org/#/c/glusterfs/+/22738/
14f8ab
>Change-Id: Ic61a8fdd0e941e136c98376a87b5a77fa8c22316
14f8ab
>Signed-off-by: Xie Changlong <xiechanglong@cmss.chinamobile.com>
14f8ab
14f8ab
BUG: 1781543
14f8ab
Change-Id: I601ebb6cd6744a61c64edd3d21d3b9a0edf1e95b
14f8ab
Signed-off-by: Rinku Kothiya <rkothiya@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/195611
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 libglusterfs/src/inode.c | 11 ++++++-----
14f8ab
 1 file changed, 6 insertions(+), 5 deletions(-)
14f8ab
14f8ab
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
14f8ab
index 5331e93..9dbb25b 100644
14f8ab
--- a/libglusterfs/src/inode.c
14f8ab
+++ b/libglusterfs/src/inode.c
14f8ab
@@ -402,14 +402,15 @@ __inode_ctx_free(inode_t *inode)
14f8ab
         goto noctx;
14f8ab
     }
14f8ab
 
14f8ab
-    for (index = 0; index < inode->table->xl->graph->xl_count; index++) {
14f8ab
+    for (index = 0; index < inode->table->ctxcount; index++) {
14f8ab
         if (inode->_ctx[index].value1 || inode->_ctx[index].value2) {
14f8ab
             xl = (xlator_t *)(long)inode->_ctx[index].xl_key;
14f8ab
-            old_THIS = THIS;
14f8ab
-            THIS = xl;
14f8ab
-            if (!xl->call_cleanup && xl->cbks->forget)
14f8ab
+            if (xl && !xl->call_cleanup && xl->cbks->forget) {
14f8ab
+                old_THIS = THIS;
14f8ab
+                THIS = xl;
14f8ab
                 xl->cbks->forget(xl, inode);
14f8ab
-            THIS = old_THIS;
14f8ab
+                THIS = old_THIS;
14f8ab
+            }
14f8ab
         }
14f8ab
     }
14f8ab
 
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab