1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 12:26:40 +02:00

api: remove check of NULL pointers before calling free() (issue #865)

This commit is contained in:
Sébastien Helleu
2024-04-25 00:06:08 +02:00
parent 590d9453a0
commit b56b34711d
5 changed files with 63 additions and 200 deletions
+37 -147
View File
@@ -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;
}