e7a346
From 63aa90525f8f408526ee5e16c42dcc976245eca7 Mon Sep 17 00:00:00 2001
e7a346
From: Mohit Agrawal <moagrawa@redhat.com>
e7a346
Date: Thu, 22 Nov 2018 18:28:35 +0530
e7a346
Subject: [PATCH 451/451] core: Resolve memory leak at the time of graph init
e7a346
e7a346
Problem: In the commit 751b14f2bfd40e08ad395ccd98c6eb0a41ac4e91
e7a346
         one code path is missed to avoid leak at the time
e7a346
         of calling graph init
e7a346
e7a346
Solution: Before destroying graph call xlator fini to avoid leak for
e7a346
          server-side xlators those call init during graph init
e7a346
e7a346
> Credit: Pranith Kumar Karampuri
e7a346
> fixes: bz#1651431
e7a346
e7a346
> Change-Id: I6e7cff0d792ab9d954524b28667e94f2d9ec19a2
e7a346
> Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
e7a346
> (Cherry pick from commit 12285e76e8f93ef6f6aa2611869bd1f40955dc9e)
e7a346
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/21695/)
e7a346
e7a346
Change-Id: Ie81635622552d43f41bbbaf810c5009a2c772a31
e7a346
BUG: 1650138
e7a346
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/156609
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 glusterfsd/src/glusterfsd.c | 36 +++++++++++++++++++++++++++++++++---
e7a346
 1 file changed, 33 insertions(+), 3 deletions(-)
e7a346
e7a346
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
e7a346
index 262a0c1..2e43cdb 100644
e7a346
--- a/glusterfsd/src/glusterfsd.c
e7a346
+++ b/glusterfsd/src/glusterfsd.c
e7a346
@@ -2338,6 +2338,23 @@ out:
e7a346
 }
e7a346
 #endif
e7a346
 
e7a346
+int
e7a346
+glusterfs_graph_fini(glusterfs_graph_t *graph)
e7a346
+{
e7a346
+    xlator_t *trav = NULL;
e7a346
+
e7a346
+    trav = graph->first;
e7a346
+
e7a346
+    while (trav) {
e7a346
+        if (trav->init_succeeded) {
e7a346
+            trav->fini(trav);
e7a346
+            trav->init_succeeded = 0;
e7a346
+        }
e7a346
+        trav = trav->next;
e7a346
+    }
e7a346
+
e7a346
+    return 0;
e7a346
+}
e7a346
 
e7a346
 int
e7a346
 glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp)
e7a346
@@ -2384,10 +2401,23 @@ out:
e7a346
                 fclose (fp);
e7a346
 
e7a346
         if (ret) {
e7a346
-                if (graph && (ctx && (ctx->active != graph)))
e7a346
-                        glusterfs_graph_destroy (graph);
e7a346
+                /* TODO This code makes to generic for all graphs
e7a346
+                   client as well as servers.For now it destroys
e7a346
+                   graph only for server-side xlators not for client-side
e7a346
+                   xlators, before destroying a graph call xlator fini for
e7a346
+                   xlators those call xlator_init to avoid leak
e7a346
+                */
e7a346
+                if (graph) {
e7a346
+                        xl = graph->first;
e7a346
+                        if ((ctx && (ctx->active != graph)) &&
e7a346
+                            (xl && !strcmp(xl->type, "protocol/server"))) {
e7a346
+                                glusterfs_graph_fini(graph);
e7a346
+                                glusterfs_graph_destroy(graph);
e7a346
+                        }
e7a346
+                }
e7a346
+
e7a346
                 /* there is some error in setting up the first graph itself */
e7a346
-                if (!ctx->active) {
e7a346
+                if (!ctx || !ctx->active) {
e7a346
                         emancipate (ctx, ret);
e7a346
                         cleanup_and_exit (ret);
e7a346
                 }
e7a346
-- 
e7a346
1.8.3.1
e7a346