diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-08-09 23:17:25 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-08-09 23:17:25 +0200 |
commit | 27dd6cf72f225b2a23d735e2111f11f02515001a (patch) | |
tree | f47dbfaf81011c187fb79c6701466c14b72157e2 /src | |
parent | b78b5575c3eeb3a61d078b1848c4167f65ee3b93 (diff) | |
download | weechat-27dd6cf72f225b2a23d735e2111f11f02515001a.zip |
core: fix memory leak in completion of config options values
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-completion.c | 395 |
1 files changed, 199 insertions, 196 deletions
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index 7301ffde9..d4b77127d 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -910,231 +910,234 @@ completion_list_add_config_option_values_cb (void *data, (void) completion_item; (void) buffer; - if (completion->args) - { - pos_space = strchr (completion->args, ' '); - if (pos_space) - option_full_name = string_strndup (completion->args, - pos_space - completion->args); - else - option_full_name = strdup (completion->args); + if (!completion->args) + return WEECHAT_RC_OK; - if (option_full_name) - { - file = NULL; - section = NULL; - pos_option = NULL; + pos_space = strchr (completion->args, ' '); + if (pos_space) + option_full_name = string_strndup (completion->args, + pos_space - completion->args); + else + option_full_name = strdup (completion->args); - pos_section = strchr (option_full_name, '.'); - pos_option = (pos_section) ? strchr (pos_section + 1, '.') : NULL; + if (!option_full_name) + return WEECHAT_RC_OK; - if (pos_section && pos_option) - { - file = string_strndup (option_full_name, - pos_section - option_full_name); - section = string_strndup (pos_section + 1, - pos_option - pos_section - 1); - pos_option++; - } - if (file && section && pos_option) + file = NULL; + section = NULL; + pos_option = NULL; + + pos_section = strchr (option_full_name, '.'); + pos_option = (pos_section) ? strchr (pos_section + 1, '.') : NULL; + + if (pos_section && pos_option) + { + file = string_strndup (option_full_name, + pos_section - option_full_name); + section = string_strndup (pos_section + 1, + pos_option - pos_section - 1); + pos_option++; + } + if (file && section && pos_option) + { + ptr_config = config_file_search (file); + if (ptr_config) + { + ptr_section = config_file_search_section (ptr_config, + section); + if (ptr_section) { - ptr_config = config_file_search (file); - if (ptr_config) + config_file_search_section_option (ptr_config, + ptr_section, + pos_option, + §ion_found, + &option_found); + if (option_found) { - ptr_section = config_file_search_section (ptr_config, - section); - if (ptr_section) + switch (option_found->type) { - config_file_search_section_option (ptr_config, - ptr_section, - pos_option, - §ion_found, - &option_found); - if (option_found) - { - switch (option_found->type) + case CONFIG_OPTION_TYPE_BOOLEAN: + gui_completion_list_add (completion, "on", + 0, WEECHAT_LIST_POS_SORT); + gui_completion_list_add (completion, "off", + 0, WEECHAT_LIST_POS_SORT); + gui_completion_list_add (completion, "toggle", + 0, WEECHAT_LIST_POS_END); + if (option_found->value) { - case CONFIG_OPTION_TYPE_BOOLEAN: + if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE) gui_completion_list_add (completion, "on", - 0, WEECHAT_LIST_POS_SORT); + 0, WEECHAT_LIST_POS_BEGINNING); + else gui_completion_list_add (completion, "off", + 0, WEECHAT_LIST_POS_BEGINNING); + } + else + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); + } + break; + case CONFIG_OPTION_TYPE_INTEGER: + if (option_found->string_values) + { + for (i = 0; option_found->string_values[i]; i++) + { + gui_completion_list_add (completion, + option_found->string_values[i], 0, WEECHAT_LIST_POS_SORT); - gui_completion_list_add (completion, "toggle", - 0, WEECHAT_LIST_POS_END); - if (option_found->value) - { - if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE) - gui_completion_list_add (completion, "on", - 0, WEECHAT_LIST_POS_BEGINNING); - else - gui_completion_list_add (completion, "off", - 0, WEECHAT_LIST_POS_BEGINNING); - } - else - { - gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, - 0, WEECHAT_LIST_POS_BEGINNING); - } - break; - case CONFIG_OPTION_TYPE_INTEGER: - if (option_found->string_values) - { - for (i = 0; option_found->string_values[i]; i++) - { - gui_completion_list_add (completion, - option_found->string_values[i], - 0, WEECHAT_LIST_POS_SORT); - } - gui_completion_list_add (completion, "++1", - 0, WEECHAT_LIST_POS_END); - gui_completion_list_add (completion, "--1", - 0, WEECHAT_LIST_POS_END); - if (option_found->value) - { - gui_completion_list_add (completion, - option_found->string_values[CONFIG_INTEGER(option_found)], - 0, WEECHAT_LIST_POS_BEGINNING); - } - else - { - gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, - 0, WEECHAT_LIST_POS_BEGINNING); - } - } - else - { - if (option_found->value && CONFIG_INTEGER(option_found) > option_found->min) - gui_completion_list_add (completion, "--1", - 0, WEECHAT_LIST_POS_BEGINNING); - if (option_found->value && CONFIG_INTEGER(option_found) < option_found->max) - gui_completion_list_add (completion, "++1", - 0, WEECHAT_LIST_POS_BEGINNING); - if (option_found->value) - { - length = 64; - value_string = malloc (length); - if (value_string) - { - snprintf (value_string, length, - "%d", CONFIG_INTEGER(option_found)); - gui_completion_list_add (completion, - value_string, - 0, WEECHAT_LIST_POS_BEGINNING); - free (value_string); - } - } - else - { - gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, - 0, WEECHAT_LIST_POS_BEGINNING); - } - } - break; - case CONFIG_OPTION_TYPE_STRING: + } + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_END); + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_END); + if (option_found->value) + { gui_completion_list_add (completion, - "\"\"", + option_found->string_values[CONFIG_INTEGER(option_found)], 0, WEECHAT_LIST_POS_BEGINNING); - if (option_found->value) - { - length = strlen (CONFIG_STRING(option_found)) + 2 + 1; - value_string = malloc (length); - if (value_string) - { - snprintf (value_string, length, - "\"%s\"", - CONFIG_STRING(option_found)); - gui_completion_list_add (completion, - value_string, - 0, WEECHAT_LIST_POS_BEGINNING); - free (value_string); - } - } - else + } + else + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); + } + } + else + { + if (option_found->value && CONFIG_INTEGER(option_found) > option_found->min) + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value && CONFIG_INTEGER(option_found) < option_found->max) + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value) + { + length = 64; + value_string = malloc (length); + if (value_string) { + snprintf (value_string, length, + "%d", CONFIG_INTEGER(option_found)); gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, + value_string, 0, WEECHAT_LIST_POS_BEGINNING); + free (value_string); } - break; - case CONFIG_OPTION_TYPE_COLOR: - num_colors = gui_color_get_weechat_colors_number (); - for (i = 0; i < num_colors; i++) - { - color_name = gui_color_get_name (i); - if (color_name) - { - gui_completion_list_add (completion, - color_name, - 0, WEECHAT_LIST_POS_SORT); - } - } - num_colors = gui_color_get_term_colors (); - for (i = 0; i <= num_colors; i++) - { - color_palette = gui_color_palette_get (i); - if (color_palette) - { - gui_completion_list_add (completion, - color_palette->alias, - 0, WEECHAT_LIST_POS_END); - } - else - { - snprintf (str_number, - sizeof (str_number), - "%d", - i); - gui_completion_list_add (completion, - str_number, - 0, WEECHAT_LIST_POS_END); - } - } - gui_completion_list_add (completion, "++1", + } + else + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); + } + } + break; + case CONFIG_OPTION_TYPE_STRING: + gui_completion_list_add (completion, + "\"\"", + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value) + { + length = strlen (CONFIG_STRING(option_found)) + 2 + 1; + value_string = malloc (length); + if (value_string) + { + snprintf (value_string, length, + "\"%s\"", + CONFIG_STRING(option_found)); + gui_completion_list_add (completion, + value_string, + 0, WEECHAT_LIST_POS_BEGINNING); + free (value_string); + } + } + else + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); + } + break; + case CONFIG_OPTION_TYPE_COLOR: + num_colors = gui_color_get_weechat_colors_number (); + for (i = 0; i < num_colors; i++) + { + color_name = gui_color_get_name (i); + if (color_name) + { + gui_completion_list_add (completion, + color_name, + 0, WEECHAT_LIST_POS_SORT); + } + } + num_colors = gui_color_get_term_colors (); + for (i = 0; i <= num_colors; i++) + { + color_palette = gui_color_palette_get (i); + if (color_palette) + { + gui_completion_list_add (completion, + color_palette->alias, 0, WEECHAT_LIST_POS_END); - gui_completion_list_add (completion, "--1", + } + else + { + snprintf (str_number, + sizeof (str_number), + "%d", + i); + gui_completion_list_add (completion, + str_number, 0, WEECHAT_LIST_POS_END); - if (option_found->value) - { - color_name = gui_color_get_name (CONFIG_INTEGER(option_found)); - if (color_name) - { - gui_completion_list_add (completion, - color_name, - 0, WEECHAT_LIST_POS_BEGINNING); - } - } - else - { - gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, - 0, WEECHAT_LIST_POS_BEGINNING); - } - break; - case CONFIG_NUM_OPTION_TYPES: - break; + } + } + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_END); + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_END); + if (option_found->value) + { + color_name = gui_color_get_name (CONFIG_INTEGER(option_found)); + if (color_name) + { + gui_completion_list_add (completion, + color_name, + 0, WEECHAT_LIST_POS_BEGINNING); + } } - if (option_found->value - && option_found->null_value_allowed) + else { gui_completion_list_add (completion, WEECHAT_CONFIG_OPTION_NULL, - 0, - WEECHAT_LIST_POS_END); + 0, WEECHAT_LIST_POS_BEGINNING); } - } + break; + case CONFIG_NUM_OPTION_TYPES: + break; + } + if (option_found->value + && option_found->null_value_allowed) + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, + WEECHAT_LIST_POS_END); } } } - if (file) - free (file); - if (section) - free (section); } } + if (file) + free (file); + if (section) + free (section); + + free (option_full_name); + return WEECHAT_RC_OK; } |