diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-25 00:06:08 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-25 20:59:25 +0200 |
commit | b56b34711dfb3bacee31265e4aa28f3c1d2a7bab (patch) | |
tree | a125ee175f717c1fa40225d9e858abaf5b22b92f | |
parent | 590d9453a0a4f7b9ad28ba829c48ee20695b2c80 (diff) | |
download | weechat-b56b34711dfb3bacee31265e4aa28f3c1d2a7bab.zip |
api: remove check of NULL pointers before calling free() (issue #865)
-rw-r--r-- | src/plugins/plugin-api-info.c | 3 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 7 | ||||
-rw-r--r-- | src/plugins/plugin-script-api.c | 184 | ||||
-rw-r--r-- | src/plugins/plugin-script.c | 42 | ||||
-rw-r--r-- | src/plugins/plugin.c | 27 |
5 files changed, 63 insertions, 200 deletions
diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index f059b2782..bc887aa9e 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -1121,8 +1121,7 @@ plugin_api_info_totp_generate_cb (const void *pointer, void *data, error: if (argv) string_free_split (argv); - if (totp) - free (totp); + free (totp); return NULL; } diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 801a17591..6677a9717 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -67,9 +67,7 @@ plugin_api_charset_set (struct t_weechat_plugin *plugin, const char *charset) if (!plugin || !charset) return; - if (plugin->charset) - free (plugin->charset); - + free (plugin->charset); plugin->charset = (charset) ? strdup (charset) : NULL; } @@ -433,8 +431,7 @@ plugin_api_command_options (struct t_weechat_plugin *plugin, split_newline, delay); - if (command2) - free (command2); + free (command2); return rc; } diff --git a/src/plugins/plugin-script-api.c b/src/plugins/plugin-script-api.c index 18844ecc6..9c652ee95 100644 --- a/src/plugins/plugin-script-api.c +++ b/src/plugins/plugin-script-api.c @@ -41,9 +41,7 @@ plugin_script_api_charset_set (struct t_plugin_script *script, if (!script) return; - if (script->charset) - free (script->charset); - + free (script->charset); script->charset = (charset) ? strdup (charset) : NULL; } @@ -248,16 +246,11 @@ plugin_script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, if (!new_section) { - if (function_and_data_read) - free (function_and_data_read); - if (function_and_data_write) - free (function_and_data_write); - if (function_and_data_write_default) - free (function_and_data_write_default); - if (function_and_data_create_option) - free (function_and_data_create_option); - if (function_and_data_delete_option) - free (function_and_data_delete_option); + free (function_and_data_read); + free (function_and_data_write); + free (function_and_data_write_default); + free (function_and_data_create_option); + free (function_and_data_delete_option); } return new_section; @@ -328,12 +321,9 @@ plugin_script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, if (!new_option) { - if (function_and_data_check_value) - free (function_and_data_check_value); - if (function_and_data_change) - free (function_and_data_change); - if (function_and_data_delete) - free (function_and_data_delete); + free (function_and_data_check_value); + free (function_and_data_change); + free (function_and_data_delete); } return new_option; @@ -357,8 +347,7 @@ plugin_script_api_printf (struct t_weechat_plugin *weechat_plugin, buf2 = (script && script->charset && script->charset[0]) ? weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_printf (buffer, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -384,8 +373,7 @@ plugin_script_api_printf_date_tags (struct t_weechat_plugin *weechat_plugin, weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_printf_date_tags (buffer, date, tags, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -412,8 +400,7 @@ plugin_script_api_printf_datetime_tags (struct t_weechat_plugin *weechat_plugin, weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_printf_datetime_tags (buffer, date, date_usec, tags, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -437,8 +424,7 @@ plugin_script_api_printf_y (struct t_weechat_plugin *weechat_plugin, buf2 = (script && script->charset && script->charset[0]) ? weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_printf_y (buffer, y, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -464,8 +450,7 @@ plugin_script_api_printf_y_date_tags (struct t_weechat_plugin *weechat_plugin, weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_printf_y_date_tags (buffer, y, date, tags, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -493,8 +478,7 @@ plugin_script_api_printf_y_datetime_tags (struct t_weechat_plugin *weechat_plugi weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_printf_y_datetime_tags (buffer, y, date, date_usec, tags, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -517,8 +501,7 @@ plugin_script_api_log_printf (struct t_weechat_plugin *weechat_plugin, buf2 = (script && script->charset && script->charset[0]) ? weechat_iconv_to_internal (script->charset, vbuffer) : NULL; weechat_log_printf ("%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); + free (buf2); free (vbuffer); } @@ -556,14 +539,9 @@ plugin_script_api_hook_command (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -597,14 +575,9 @@ plugin_script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -637,14 +610,9 @@ plugin_script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -678,14 +646,9 @@ plugin_script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -724,14 +687,9 @@ plugin_script_api_hook_process_hashtable (struct t_weechat_plugin *weechat_plugi function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -793,14 +751,9 @@ plugin_script_api_hook_url (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -844,14 +797,9 @@ plugin_script_api_hook_connect (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -886,14 +834,9 @@ plugin_script_api_hook_line (struct t_weechat_plugin *weechat_plugin, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -935,14 +878,9 @@ plugin_script_api_hook_print (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -977,14 +915,9 @@ plugin_script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1018,14 +951,9 @@ plugin_script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1059,14 +987,9 @@ plugin_script_api_hook_config (struct t_weechat_plugin *weechat_plugin, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1102,14 +1025,9 @@ plugin_script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1144,14 +1062,9 @@ plugin_script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1187,14 +1100,9 @@ plugin_script_api_hook_info (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1234,14 +1142,9 @@ plugin_script_api_hook_info_hashtable (struct t_weechat_plugin *weechat_plugin, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1280,14 +1183,9 @@ plugin_script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1319,14 +1217,9 @@ plugin_script_api_hook_focus (struct t_weechat_plugin *weechat_plugin, new_hook = weechat_hook_focus (area, callback, script, function_and_data); if (new_hook) - { weechat_hook_set (new_hook, "subplugin", script->name); - } else - { - if (function_and_data) - free (function_and_data); - } + free (function_and_data); return new_hook; } @@ -1389,10 +1282,8 @@ plugin_script_api_buffer_new_props (struct t_weechat_plugin *weechat_plugin, } else { - if (function_and_data_input) - free (function_and_data_input); - if (function_and_data_close) - free (function_and_data_close); + free (function_and_data_input); + free (function_and_data_close); } return new_buffer; @@ -1505,8 +1396,7 @@ plugin_script_api_command_options (struct t_weechat_plugin *weechat_plugin, (command2) ? command2 : command, options); - if (command2) - free (command2); + free (command2); return rc; } diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c index 6ea597f57..809b9cd67 100644 --- a/src/plugins/plugin-script.c +++ b/src/plugins/plugin-script.c @@ -270,8 +270,7 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin, N_("Without argument, this command lists all loaded scripts.")), completion, plugin_data->callback_command, NULL, NULL); - if (completion) - free (completion); + free (completion); /* add completion, hdata and infolist */ snprintf (string, sizeof (string), "%s_script", weechat_plugin->name); @@ -323,8 +322,7 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin, auto_load_scripts = (info_auto_load_scripts && (strcmp (info_auto_load_scripts, "1") == 0)) ? 1 : 0; - if (info_auto_load_scripts) - free (info_auto_load_scripts); + free (info_auto_load_scripts); /* autoload scripts */ if (auto_load_scripts) @@ -1067,22 +1065,14 @@ plugin_script_remove_configs (struct t_weechat_plugin *weechat_plugin, void plugin_script_free (struct t_plugin_script *script) { - if (script->filename) - free (script->filename); - if (script->name) - free (script->name); - if (script->author) - free (script->author); - if (script->version) - free (script->version); - if (script->license) - free (script->license); - if (script->description) - free (script->description); - if (script->shutdown_func) - free (script->shutdown_func); - if (script->charset) - free (script->charset); + free (script->filename); + free (script->name); + free (script->author); + free (script->version); + free (script->license); + free (script->description); + free (script->shutdown_func); + free (script->charset); free (script); } @@ -1369,8 +1359,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin, free (symlink_path); } free (autoload_path); - if (dir_separator) - free (dir_separator); + free (dir_separator); } } @@ -1397,8 +1386,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin, free (new_path); } free (base_name); - if (weechat_data_dir) - free (weechat_data_dir); + free (weechat_data_dir); /* send signal */ snprintf (str_signal, sizeof (str_signal), @@ -1569,8 +1557,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin, (void) rc; free (symlink_path); } - if (dir_separator) - free (dir_separator); + free (dir_separator); } else { @@ -1579,8 +1566,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin, free (autoload_path); } free (base_name); - if (weechat_data_dir) - free (weechat_data_dir); + free (weechat_data_dir); } free (name); } diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index d885774b8..01edcf744 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -382,8 +382,7 @@ plugin_call_init (struct t_weechat_plugin *plugin, int argc, char **argv) weechat_auto_connect = old_auto_connect; weechat_auto_load_scripts = old_auto_load_scripts; - if (plugin_argv) - free (plugin_argv); + free (plugin_argv); return (rc == WEECHAT_RC_OK) ? 1 : 0; } @@ -1221,22 +1220,15 @@ plugin_remove (struct t_weechat_plugin *plugin) gui_bar_item_free_all_plugin (plugin); /* free data */ - if (plugin->filename) - free (plugin->filename); + free (plugin->filename); if (!weechat_plugin_no_dlclose) dlclose (plugin->handle); - if (plugin->name) - free (plugin->name); - if (plugin->description) - free (plugin->description); - if (plugin->author) - free (plugin->author); - if (plugin->version) - free (plugin->version); - if (plugin->license) - free (plugin->license); - if (plugin->charset) - free (plugin->charset); + free (plugin->name); + free (plugin->description); + free (plugin->author); + free (plugin->version); + free (plugin->license); + free (plugin->charset); hashtable_free (plugin->variables); free (plugin); @@ -1273,8 +1265,7 @@ plugin_unload (struct t_weechat_plugin *plugin) } (void) hook_signal_send ("plugin_unloaded", WEECHAT_HOOK_SIGNAL_STRING, name); - if (name) - free (name); + free (name); } /* |