diff options
author | Kotresh HR <khiremat@redhat.com> | 2018-12-05 12:55:14 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-12-06 10:27:37 +0000 |
commit | 36e1175df6f404aad89b8a802d4f603ebaa3515b (patch) | |
tree | e19d7844d730db1b74950d31c33e80465f371b36 | |
parent | 340e58f9b3bcdfe4314da65e592dcd5c2daf6fd9 (diff) |
cli: Fix mem-leaks reported by ASAN
Tracebacks:
Direct leak of 96 byte(s) in 1 object(s) allocated from:
#0 0x7f3acf9eac48 in malloc (/lib64/libasan.so.5+0xeec48)
#1 0x7f3acf510949 in __gf_malloc ./libglusterfs/src/mem-pool.c:136
#2 0x7f3acf5111bb in gf_vasprintf ./libglusterfs/src/mem-pool.c:236
#3 0x7f3acf51138a in gf_asprintf ./libglusterfs/src/mem-pool.c:256
#4 0x421611 in cli_cmd_volume_set_cbk ./cli/src/cli-cmd-volume.c:868
#5 0x410599 in cli_cmd_process ./cli/src/cli-cmd.c:135
#6 0x40f90d in cli_batch ./cli/src/input.c:29
#7 0x7f3acd78c593 in start_thread pthread_create.c:463
Direct leak of 73 byte(s) in 1 object(s) allocated from:
#0 0x7f3acf9eac48 in malloc (/lib64/libasan.so.5+0xeec48)
#1 0x7f3acf510949 in __gf_malloc ./libglusterfs/src/mem-pool.c:136
#2 0x421519 in gf_strndup ../../libglusterfs/src/mem-pool.h:167
#3 0x421519 in gf_strdup ../../libglusterfs/src/mem-pool.h:184
#4 0x421519 in cli_cmd_volume_set_cbk cli/src/cli-cmd-volume.c:859
#5 0x410599 in cli_cmd_process cli/src/cli-cmd.c:135
#6 0x40f90d in cli_batch cli/src/input.c:29
#7 0x7f3acd78c593 in start_thread pthread_create.c:463
Change-Id: I3312751c1e3178672360a678fe15b1f7f1054b22
updates: bz#1633930
Signed-off-by: Kotresh HR <khiremat@redhat.com>
-rw-r--r-- | cli/src/cli-cmd-volume.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 9655202b668..ebabebf2e4f 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -857,8 +857,14 @@ out: else num_options = num_options / 2; + char *free_list_key[num_options]; + char *free_list_val[num_options]; + for (i = 0; i < num_options; i++) { + free_list_key[i] = NULL; + free_list_val[i] = NULL; + } /* Initialize opts_str */ - opts_str = gf_strdup(""); + opts_str = ""; /* Prepare String in format options=KEY1,VALUE1,KEY2,VALUE2 */ for (i = 1; i <= num_options; i++) { @@ -868,6 +874,7 @@ out: tmp_opt = ""; gf_asprintf(&opts_str, "%s,%s", opts_str, tmp_opt); + free_list_key[i - 1] = opts_str; sprintf(dict_key, "value%d", i); ret1 = dict_get_str(options, dict_key, &tmp_opt); @@ -875,13 +882,17 @@ out: tmp_opt = ""; gf_asprintf(&opts_str, "%s,%s", opts_str, tmp_opt); + free_list_val[i - 1] = opts_str; } gf_event(EVENT_VOLUME_SET, "name=%s;options=%s", (char *)words[2], opts_str); /* Allocated by gf_strdup and gf_asprintf */ - GF_FREE(opts_str); + for (i = 0; i < num_options; i++) { + GF_FREE(free_list_key[i]); + GF_FREE(free_list_val[i]); + } } #endif |