diff options
| author | Mohit Agrawal <moagrawal@redhat.com> | 2018-11-21 19:02:42 +0530 | 
|---|---|---|
| committer | Xavi Hernandez <xhernandez@redhat.com> | 2018-11-22 12:51:49 +0000 | 
| commit | 12285e76e8f93ef6f6aa2611869bd1f40955dc9e (patch) | |
| tree | d8ada4cca45d3831de8898696bfc80e0cde71080 /glusterfsd/src | |
| parent | 429843eb9e3685d11479c58b8bc6416889a01ee3 (diff) | |
core: Resolve memory leak at the time of graph init
Problem: In the commit 751b14f2bfd40e08ad395ccd98c6eb0a41ac4e91
         one code path is missed to avoid leak at the time
         of calling graph init
Solution: Before destroying graph call xlator fini to avoid leak for
          server-side xlators those call init during graph init
Credit: Pranith Kumar Karampuri
fixes: bz#1651431
Change-Id: I6e7cff0d792ab9d954524b28667e94f2d9ec19a2
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
Diffstat (limited to 'glusterfsd/src')
| -rw-r--r-- | glusterfsd/src/glusterfsd.c | 37 | 
1 files changed, 34 insertions, 3 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 106bfe3bcc1..a1626a81e9f 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -2538,6 +2538,24 @@ out:  #endif  int +glusterfs_graph_fini(glusterfs_graph_t *graph) +{ +    xlator_t *trav = NULL; + +    trav = graph->first; + +    while (trav) { +        if (trav->init_succeeded) { +            trav->fini(trav); +            trav->init_succeeded = 0; +        } +        trav = trav->next; +    } + +    return 0; +} + +int  glusterfs_process_volfp(glusterfs_ctx_t *ctx, FILE *fp)  {      glusterfs_graph_t *graph = NULL; @@ -2584,10 +2602,23 @@ out:          fclose(fp);      if (ret) { -        if (graph && (ctx && (ctx->active != graph))) -            glusterfs_graph_destroy(graph); +        /* TODO This code makes to generic for all graphs +           client as well as servers.For now it destroys +           graph only for server-side xlators not for client-side +           xlators, before destroying a graph call xlator fini for +           xlators those call xlator_init to avoid leak +        */ +        if (graph) { +            xl = graph->first; +            if ((ctx && (ctx->active != graph)) && +                (xl && !strcmp(xl->type, "protocol/server"))) { +                glusterfs_graph_fini(graph); +                glusterfs_graph_destroy(graph); +            } +        } +          /* there is some error in setting up the first graph itself */ -        if (!ctx->active) { +        if (!ctx || !ctx->active) {              emancipate(ctx, ret);              cleanup_and_exit(ret);          }  | 
