diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-24 23:55:43 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-25 20:59:25 +0200 |
commit | ea85d180e5fc4a23bd7beef64f21f5b376fbce32 (patch) | |
tree | 78e6ab85d45bd61011abf130fb10bb85fc25413e /src/plugins | |
parent | 0e3b6a9c774c8f9587fd00acfb5716a520783d84 (diff) | |
download | weechat-ea85d180e5fc4a23bd7beef64f21f5b376fbce32.zip |
trigger: remove check of NULL pointers before calling free() (issue #865)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/trigger/trigger-buffer.c | 3 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 21 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-command.c | 27 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-config.c | 3 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.c | 39 |
5 files changed, 31 insertions, 62 deletions
diff --git a/src/plugins/trigger/trigger-buffer.c b/src/plugins/trigger/trigger-buffer.c index d96ec1d24..70c404cfe 100644 --- a/src/plugins/trigger/trigger-buffer.c +++ b/src/plugins/trigger/trigger-buffer.c @@ -287,8 +287,7 @@ trigger_buffer_hashtable_map_cb (void *data, weechat_color ("reset"), (value_no_color) ? value_no_color : (const char *)value, weechat_color ("chat_delimiters")); - if (value_no_color) - free (value_no_color); + free (value_no_color); } else if (strcmp (value_type, "pointer") == 0) { diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index 6cb12b672..ea67af15f 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -271,8 +271,7 @@ trigger_callback_check_conditions (struct t_trigger *trigger, extra_vars, trigger_callback_hashtable_options_conditions); rc = (value && (strcmp (value, "1") == 0)); - if (value) - free (value); + free (value); return rc; } @@ -347,10 +346,8 @@ trigger_callback_regex_translate_chars (struct t_trigger_context *context, value = weechat_string_translate_chars (text, chars1_eval, chars2_eval); - if (chars1_eval) - free (chars1_eval); - if (chars2_eval) - free (chars2_eval); + free (chars1_eval); + free (chars2_eval); return value; } @@ -706,8 +703,7 @@ trigger_callback_signal_cb (const void *pointer, void *data, weechat_hashtable_set (ctx.pointers, "irc_channel", ptr_irc_channel); } } - if (irc_server_name) - free (irc_server_name); + free (irc_server_name); /* create hashtable (if not already created) */ if (!ctx.extra_vars) @@ -987,8 +983,7 @@ end: if (tags) weechat_string_free_split (tags); - if (string_no_color) - free (string_no_color); + free (string_no_color); TRIGGER_CALLBACK_CB_END(string_modified); } @@ -1058,15 +1053,13 @@ trigger_callback_line_cb (const void *pointer, void *data, ptr_value = weechat_hashtable_get (line, "prefix"); string_no_color = weechat_string_remove_color (ptr_value, NULL); weechat_hashtable_set (ctx.extra_vars, "tg_prefix_nocolor", string_no_color); - if (string_no_color) - free (string_no_color); + free (string_no_color); /* build message without colors */ ptr_value = weechat_hashtable_get (line, "message"); string_no_color = weechat_string_remove_color (ptr_value, NULL); weechat_hashtable_set (ctx.extra_vars, "tg_message_nocolor", string_no_color); - if (string_no_color) - free (string_no_color); + free (string_no_color); if (!trigger_callback_set_tags (ctx.buffer, (const char **)tags, num_tags, ctx.extra_vars)) diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index 504697591..7a160180d 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -568,10 +568,8 @@ trigger_command_rename (struct t_trigger *trigger, const char *new_name) } end: - if (name) - free (name); - if (name2) - free (name2); + free (name); + free (name2); } /* @@ -892,18 +890,12 @@ trigger_command_trigger (const void *pointer, void *data, arg_command, arg_return_code, arg_post_action); - if (arg_arguments) - free (arg_arguments); - if (arg_conditions) - free (arg_conditions); - if (arg_regex) - free (arg_regex); - if (arg_command) - free (arg_command); - if (arg_return_code) - free (arg_return_code); - if (arg_post_action) - free (arg_post_action); + free (arg_arguments); + free (arg_conditions); + free (arg_regex); + free (arg_command); + free (arg_return_code); + free (arg_post_action); if (input) { if (weechat_strcmp (argv[1], "output") == 0) @@ -1121,8 +1113,7 @@ trigger_command_trigger (const void *pointer, void *data, weechat_printf_date_tags (NULL, 0, "no_trigger", _("Trigger \"%s\" removed"), name); - if (name) - free (name); + free (name); } } ptr_trigger = ptr_next_trigger; diff --git a/src/plugins/trigger/trigger-config.c b/src/plugins/trigger/trigger-config.c index cbe648617..c9f2fff3d 100644 --- a/src/plugins/trigger/trigger-config.c +++ b/src/plugins/trigger/trigger-config.c @@ -532,8 +532,7 @@ trigger_config_use_temp_triggers () { next_temp_trigger = triggers_temp->next_trigger; - if (triggers_temp->name) - free (triggers_temp->name); + free (triggers_temp->name); free (triggers_temp); triggers_temp = next_temp_trigger; diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index 06fc663f8..afdb292d8 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -460,14 +460,10 @@ trigger_hook (struct t_trigger *trigger) (eval_completion) ? eval_completion : "", &trigger_callback_command_cb, trigger, NULL); - if (eval_desc) - free (eval_desc); - if (eval_args) - free (eval_args); - if (eval_desc_args) - free (eval_desc_args); - if (eval_completion) - free (eval_completion); + free (eval_desc); + free (eval_args); + free (eval_desc_args); + free (eval_completion); if (extra_vars) weechat_hashtable_free (extra_vars); } @@ -626,19 +622,15 @@ trigger_regex_free (int *regex_count, struct t_trigger_regex **regex) { for (i = 0; i < *regex_count; i++) { - if ((*regex)[i].variable) - free ((*regex)[i].variable); - if ((*regex)[i].str_regex) - free ((*regex)[i].str_regex); + free ((*regex)[i].variable); + free ((*regex)[i].str_regex); if ((*regex)[i].regex) { regfree ((*regex)[i].regex); free ((*regex)[i].regex); } - if ((*regex)[i].replace) - free ((*regex)[i].replace); - if ((*regex)[i].replace_escaped) - free ((*regex)[i].replace_escaped); + free ((*regex)[i].replace); + free ((*regex)[i].replace_escaped); } free (*regex); *regex = NULL; @@ -758,8 +750,7 @@ trigger_regex_split (const char *str_regex, /* set regex (command "s" only) */ if (command == TRIGGER_REGEX_COMMAND_REPLACE) { - if (str_regex_escaped) - free (str_regex_escaped); + free (str_regex_escaped); str_regex_escaped = weechat_string_convert_escaped_chars ((*regex)[index].str_regex); if (!str_regex_escaped) goto memory_error; @@ -837,10 +828,8 @@ memory_error: goto end; end: - if (delimiter) - free (delimiter); - if (str_regex_escaped) - free (str_regex_escaped); + free (delimiter); + free (str_regex_escaped); if (rc < 0) trigger_regex_free (regex_count, regex); @@ -1171,8 +1160,7 @@ trigger_rename (struct t_trigger *trigger, const char *name) } } - if (trigger->name) - free (trigger->name); + free (trigger->name); trigger->name = strdup (name); free (option_name); @@ -1243,8 +1231,7 @@ trigger_free (struct t_trigger *trigger) /* free data */ trigger_unhook (trigger); trigger_regex_free (&trigger->regex_count, &trigger->regex); - if (trigger->name) - free (trigger->name); + free (trigger->name); for (i = 0; i < TRIGGER_NUM_OPTIONS; i++) { if (trigger->options[i]) |