diff options
| author | Mohit Agrawal <moagrawal@redhat.com> | 2018-11-29 19:55:39 +0530 | 
|---|---|---|
| committer | Atin Mukherjee <amukherj@redhat.com> | 2018-12-03 11:34:35 +0000 | 
| commit | 46c15ea8fa98bb3d92580b192f03863c2e2a2d9c (patch) | |
| tree | 25462a497b273a0f963e2090adbbd928a4bb9bbc /libglusterfs/src | |
| parent | f77fb6d568616592ab25501c402c140d15235ca9 (diff) | |
server: Resolve memory leak path in server_init
Problem: 1) server_init does not cleanup allocate resources
            while it is failed before return error
         2) dict leak at the time of graph destroying
Solution: 1) free resources in case of server_init is failed
          2) Take dict_ref of graph xlator before destroying
             the graph to avoid leak
Change-Id: I9e31e156b9ed6bebe622745a8be0e470774e3d15
fixes: bz#1654917
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
Diffstat (limited to 'libglusterfs/src')
| -rw-r--r-- | libglusterfs/src/libglusterfs.sym | 1 | ||||
| -rw-r--r-- | libglusterfs/src/xlator.c | 31 | ||||
| -rw-r--r-- | libglusterfs/src/xlator.h | 2 | 
3 files changed, 34 insertions, 0 deletions
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym index c8c42311c80..baf44de64ad 100644 --- a/libglusterfs/src/libglusterfs.sym +++ b/libglusterfs/src/libglusterfs.sym @@ -1121,6 +1121,7 @@ xlator_volume_option_get  xlator_volume_option_get_list  xlator_memrec_free  xlator_mem_cleanup +gluster_graph_take_reference  default_fops  gf_fop_list  gf_upcall_list diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index cbbe8cf7f12..dedce05d5c3 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -1555,3 +1555,34 @@ glusterfs_delete_volfile_checksum(glusterfs_ctx_t *ctx, const char *volfile_id)      return 0;  } + +/* +   The function is required to take dict ref for every xlator at graph. +   At the time of compare graph topology create a graph and populate +   key values in the dictionary, after finished graph comparison we do destroy +   the new graph.At the time of construct graph we don't take any reference +   so to avoid dict leak at the of destroying graph due to ref counter underflow +   we need to call dict_ref here. + +*/ + +void +gluster_graph_take_reference(xlator_t *tree) +{ +    xlator_t *trav = tree; +    xlator_t *prev = tree; + +    if (!tree) { +        gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND, +               "Translator tree not found"); +        return; +    } + +    while (prev) { +        trav = prev->next; +        if (prev->options) +            dict_ref(prev->options); +        prev = trav; +    } +    return; +} diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 64a61ac0bed..30c9e5875e5 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -1082,4 +1082,6 @@ xlator_mem_cleanup(xlator_t *this);  void  handle_default_options(xlator_t *xl, dict_t *options); +void +gluster_graph_take_reference(xlator_t *tree);  #endif /* _XLATOR_H */  | 
