diff options
author | Raghavendra Bhat <raghavendrabhat@gluster.com> | 2011-09-12 11:45:37 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2011-09-12 02:31:37 -0700 |
commit | 5d03ebd31f2984614ecdc8f117bd4599ade497d1 (patch) | |
tree | a41ec7f7dcc304083e28540941c9f16ed766834b /xlators/mgmt/glusterd/src | |
parent | 225dd7da8959c78331d16ba2c2a955b1432bc873 (diff) |
glusterd: free the allocated string to avoid memory leak
Change-Id: I520abf3c57a15be8bb7dd1e92ad0b049ef5c8970
BUG: 3341
Reviewed-on: http://review.gluster.com/394
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 60 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.h | 20 |
2 files changed, 24 insertions, 56 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 086a22fa08b..cb198dfb9fe 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -813,20 +813,7 @@ glusterd_check_voloption_flags (char *key, int32_t flags) struct volopt_map_entry *vmep = NULL; int ret = 0; - if (!strchr (key, '.')) { - ret = option_complete (key, &completion); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Out of memory"); - return _gf_false; - } - - if (!completion) { - gf_log ("", GF_LOG_ERROR, "option %s does not exist", - key); - return _gf_false; - } - } - + COMPLETE_OPTION(key, completion, ret); for (vmep = glusterd_volopt_map; vmep->key; vmep++) { if (strcmp (vmep->key, key) == 0) { if (vmep->flags & flags) @@ -846,20 +833,7 @@ glusterd_check_globaloption (char *key) struct volopt_map_entry *vmep = NULL; int ret = 0; - if (!strchr (key, '.')) { - ret = option_complete (key, &completion); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Out of memory"); - return _gf_false; - } - - if (!completion) { - gf_log ("", GF_LOG_ERROR, "option %s does not exist", - key); - return _gf_false; - } - } - + COMPLETE_OPTION(key, completion, ret); for (vmep = glusterd_volopt_map; vmep->key; vmep++) { if (strcmp (vmep->key, key) == 0) { if ((vmep->type == GLOBAL_DOC) || @@ -880,20 +854,7 @@ glusterd_check_localoption (char *key) struct volopt_map_entry *vmep = NULL; int ret = 0; - if (!strchr (key, '.')) { - ret = option_complete (key, &completion); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Out of memory"); - return _gf_false; - } - - if (!completion) { - gf_log ("", GF_LOG_ERROR, "option %s does not exist", - key); - return _gf_false; - } - } - + COMPLETE_OPTION(key, completion, ret); for (vmep = glusterd_volopt_map; vmep->key; vmep++) { if (strcmp (vmep->key, key) == 0) { if ((vmep->type == DOC) || @@ -914,20 +875,7 @@ glusterd_check_voloption (char *key) struct volopt_map_entry *vmep = NULL; int ret = 0; - if (!strchr (key, '.')) { - ret = option_complete (key, &completion); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Out of memory"); - return _gf_false; - } - - if (!completion) { - gf_log ("", GF_LOG_ERROR, "option %s does not exist", - key); - return _gf_false; - } - } - + COMPLETE_OPTION(key, completion, ret); for (vmep = glusterd_volopt_map; vmep->key; vmep++) { if (strcmp (vmep->key, key) == 0) { if ((vmep->type == DOC) || diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h index 27363984d6b..3fd8a8351df 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.h +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h @@ -36,6 +36,26 @@ #define VKEY_FEATURES_QUOTA "features.quota" #define VKEY_PERF_STAT_PREFETCH "performance.stat-prefetch" +#define COMPLETE_OPTION(key, completion, ret) \ + do { \ + if (!strchr (key, '.')) { \ + ret = option_complete (key, &completion); \ + if (ret) { \ + gf_log ("", GF_LOG_ERROR, "Out of memory"); \ + return _gf_false; \ + } \ + \ + if (!completion) { \ + gf_log ("", GF_LOG_ERROR, "option %s does not" \ + "exist", key); \ + return _gf_false; \ + } \ + } \ + \ + if (completion) \ + GF_FREE (completion); \ + } while (0); + typedef enum gd_volopt_flags_ { OPT_FLAG_NONE, OPT_FLAG_FORCE = 1, |