From bb41d03cf8a907794749cd83266461b06c1b1172 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 6 Jan 2016 14:30:08 +0530 Subject: [PATCH 640/642] dict: Don't expose get_new_dict/dict_destroy get_new_dict/dict_destroy is causing confusion where, dict_new/dict_destroy or get_new_dict/dict_unref are used instead of dict_new/dict_unref. The downstream patch only covers the dictionary changes in glusterd and cli codebase and skip the other parts as the bug is only tracked for glusterd memory leak issues. >Reviewed-on: http://review.gluster.org/13183 >Smoke: Gluster Build System >CentOS-regression: Gluster Build System >NetBSD-regression: NetBSD Build System >Reviewed-by: Jeff Darcy >Reviewed-by: Krutika Dhananjay Change-Id: I4cc69f5b6711d720823395e20fd624a0c6c1168c BUG: 1526363 Signed-off-by: Pranith Kumar K Reviewed-on: https://code.engineering.redhat.com/gerrit/125957 Tested-by: Atin Mukherjee Tested-by: RHGS Build Bot --- cli/src/cli-cmd-parser.c | 44 ++++++++++++++-------------- cli/src/cli-cmd-system.c | 6 ++-- cli/src/cli-cmd-volume.c | 2 +- cli/src/cli-rpc-ops.c | 4 +-- cli/src/cli.c | 2 +- libglusterfs/src/dict.h | 4 +-- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 4 +-- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 4 +-- xlators/mgmt/glusterd/src/glusterd-volgen.c | 12 ++++---- 9 files changed, 40 insertions(+), 42 deletions(-) diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 12717cd..0056581 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -741,7 +741,7 @@ out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI"); if (dict) - dict_destroy (dict); + dict_unref (dict); } GF_FREE (trans_type); @@ -817,7 +817,7 @@ cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) out: if (ret && dict) { - dict_destroy (dict); + dict_unref (dict); } return ret; @@ -1138,7 +1138,7 @@ cli_cmd_inode_quota_parse (const char **words, int wordcount, dict_t **options) out: if (ret < 0) { if (dict) - dict_destroy (dict); + dict_unref (dict); } return ret; @@ -1477,7 +1477,7 @@ set_type: out: if (ret < 0) { if (dict) - dict_destroy (dict); + dict_unref (dict); } return ret; @@ -1748,8 +1748,8 @@ cli_cmd_volume_set_parse (struct cli_state *state, const char **words, *options = dict; out: - if (ret) - dict_destroy (dict); + if (ret && dict) + dict_unref (dict); return ret; } @@ -1889,7 +1889,7 @@ out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI"); if (dict) - dict_destroy (dict); + dict_unref (dict); } return ret; @@ -1968,7 +1968,7 @@ out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse tier CLI"); if (dict) - dict_destroy (dict); + dict_unref (dict); } return ret; @@ -2197,7 +2197,7 @@ out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI"); if (dict) - dict_destroy (dict); + dict_unref (dict); } GF_FREE (tmp_brick); @@ -2392,7 +2392,7 @@ out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse reset-brick CLI"); if (dict) - dict_destroy (dict); + dict_unref (dict); } return ret; @@ -2453,7 +2453,7 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -2510,7 +2510,7 @@ cli_cmd_log_level_parse (const char **words, int worcount, dict_t **options) out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -2561,7 +2561,7 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -2615,7 +2615,7 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -3057,7 +3057,7 @@ out: GF_FREE (slave_temp); if (ret) { if (dict) - dict_destroy (dict); + dict_unref (dict); } else *options = dict; @@ -3154,7 +3154,7 @@ cli_cmd_volume_profile_parse (const char **words, int wordcount, *options = dict; out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -3343,7 +3343,7 @@ cli_cmd_volume_top_parse (const char **words, int wordcount, *options = dict; out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -3556,7 +3556,7 @@ cli_cmd_volume_status_parse (const char **words, int wordcount, out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -3644,7 +3644,7 @@ cli_cmd_volume_statedump_options_parse (const char **words, int wordcount, out: GF_FREE (tmp); if (ret && dict) - dict_destroy (dict); + dict_unref (dict); if (ret) gf_log ("cli", GF_LOG_ERROR, "Error parsing dumpoptions"); return ret; @@ -4134,7 +4134,7 @@ done: out: if (ret && dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -5458,7 +5458,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, out: if (ret) { if (dict) - dict_destroy (dict); + dict_unref (dict); } else *options = dict; @@ -5716,7 +5716,7 @@ out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse bitrot command"); if (dict) - dict_destroy (dict); + dict_unref (dict); } return ret; diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c index ad6bb73..93aac0b 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -66,7 +66,7 @@ cli_cmd_getspec_cbk (struct cli_state *state, struct cli_cmd_word *word, out: if (!proc && ret) { if (dict) - dict_destroy (dict); + dict_unref (dict); if (wordcount > 1) cli_out ("Fetching spec for volume %s failed", (char *)words[2]); @@ -109,7 +109,7 @@ cli_cmd_pmap_b2p_cbk (struct cli_state *state, struct cli_cmd_word *word, out: if (!proc && ret) { if (dict) - dict_destroy (dict); + dict_unref (dict); if (wordcount > 1) cli_out ("Fetching spec for volume %s failed", (char *)words[3]); @@ -188,7 +188,7 @@ make_seq_dict (int argc, char **argv) } if (ret) { - dict_destroy (dict); + dict_unref (dict); dict = NULL; } diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 3ec39fd..927c802 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -592,7 +592,7 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word, out: if (dict) - dict_destroy (dict); + dict_unref (dict); if (ret) { cli_cmd_sent_status_get (&sent); diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 7ded5f9..24037aa 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -493,7 +493,7 @@ out: cli_cmd_broadcast_response (ret); if (dict) - dict_destroy (dict); + dict_unref (dict); return ret; } @@ -1127,7 +1127,7 @@ out: cli_cmd_broadcast_response (ret); if (dict) - dict_destroy (dict); + dict_unref (dict); free (rsp.dict.dict_val); diff --git a/cli/src/cli.c b/cli/src/cli.c index e0d6b3e..33250d3 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -607,7 +607,7 @@ cli_quotad_clnt_rpc_init (void) out: if (ret) { if (rpc_opts) - dict_destroy(rpc_opts); + dict_unref(rpc_opts); } return rpc; } diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index b5d9f3e..455391a 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -156,10 +156,7 @@ char *data_to_str (data_t *data); void *data_to_bin (data_t *data); void *data_to_ptr (data_t *data); -data_t *get_new_data (); data_t * data_copy (data_t *old); -dict_t *get_new_dict_full (int size_hint); -dict_t *get_new_dict (); int dict_foreach (dict_t *this, int (*fn)(dict_t *this, @@ -193,6 +190,7 @@ int dict_null_foreach_fn (dict_t *d, char *k, int dict_remove_foreach_fn (dict_t *d, char *k, data_t *v, void *tmp); dict_t *dict_copy (dict_t *this, dict_t *new); +dict_t *get_new_dict (void); int dict_keys_join (void *value, int size, dict_t *dict, int (*filter_fn)(char *key)); diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index fa3b151..907c29f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -1976,7 +1976,7 @@ is_geo_rep_active (glusterd_volinfo_t *volinfo, char *slave, ret = 0; out: if (confd) - dict_destroy (confd); + dict_unref (confd); return ret; } @@ -2617,7 +2617,7 @@ fetch_data: } if (confd) - dict_destroy (confd); + dict_unref (confd); gf_msg_debug (this->name, 0, "Returning %d ", ret); return ret; diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 51eae2d..f034ae8 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -4369,7 +4369,7 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) if (ret) goto out; } - dict_destroy (req_dict); + dict_unref (req_dict); req_dict = dict_ref (dict); } break; @@ -4395,7 +4395,7 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) goto out; } - dict_destroy (req_dict); + dict_unref (req_dict); req_dict = dict_ref (dict); } break; diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 701cccf..859a932 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -93,7 +93,7 @@ xlator_instantiate_va (const char *type, const char *format, va_list arg) ret = xlator_set_type_virtual (xl, type); if (ret) goto error; - xl->options = get_new_dict(); + xl->options = dict_new (); if (!xl->options) goto error; xl->name = volname; @@ -1052,7 +1052,7 @@ build_graph_generic (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, int ret = 0; if (mod_dict) { - set_dict = dict_copy (volinfo->dict, NULL); + set_dict = dict_copy_with_ref (volinfo->dict, NULL); if (!set_dict) return -1; dict_copy (mod_dict, set_dict); @@ -1066,7 +1066,7 @@ build_graph_generic (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ret = volgen_graph_set_options (graph, set_dict); if (mod_dict) - dict_destroy (set_dict); + dict_unref (set_dict); return ret; } @@ -4728,7 +4728,7 @@ build_rebalance_volfile (glusterd_volinfo_t *volinfo, char *filepath, return 0; } - set_dict = dict_copy (volinfo->dict, NULL); + set_dict = dict_copy_with_ref (volinfo->dict, NULL); if (!set_dict) return -1; @@ -4770,7 +4770,7 @@ build_rebalance_volfile (glusterd_volinfo_t *volinfo, char *filepath, out: volgen_graph_free (&graph); - dict_destroy (set_dict); + dict_unref (set_dict); return ret; } @@ -5037,7 +5037,7 @@ build_nfs_graph (volgen_graph_t *graph, dict_t *mod_dict) out: gf_msg_debug ("glusterd", 0, "Returning %d", ret); - dict_destroy (set_dict); + dict_unref (set_dict); return ret; } -- 2.9.3