1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 23:06:38 +02:00

core: remove check of NULL pointers before calling string_shared_free() (issue #865)

This commit is contained in:
Sébastien Helleu
2024-04-25 19:19:43 +02:00
parent 409a06982e
commit 619b40b42f
5 changed files with 17 additions and 28 deletions
+1 -2
View File
@@ -1276,8 +1276,7 @@ hdata_set (struct t_hdata *hdata, void *pointer, const char *name,
break;
case WEECHAT_HDATA_SHARED_STRING:
ptr_string = (char **)(pointer + var->offset);
if (*ptr_string)
string_shared_free (*ptr_string);
string_shared_free (*ptr_string);
*ptr_string = (value) ? (char *)string_shared_get (value) : NULL;
return 1;
break;
+1 -2
View File
@@ -753,8 +753,7 @@ gui_chat_printf_datetime_tags_internal (struct t_gui_buffer *buffer,
new_line->data->date = new_line->data->date_printed;
new_line->data->date_usec = new_line->data->date_usec_printed;
}
if (new_line->data->prefix)
string_shared_free (new_line->data->prefix);
string_shared_free (new_line->data->prefix);
if (pos_prefix)
{
new_line->data->prefix = (char *)string_shared_get (pos_prefix);
+2 -4
View File
@@ -1246,8 +1246,7 @@ gui_line_free_data (struct t_gui_line *line)
{
free (line->data->str_time);
gui_line_tags_free (line->data);
if (line->data->prefix)
string_shared_free (line->data->prefix);
string_shared_free (line->data->prefix);
free (line->data->message);
free (line->data);
@@ -1788,8 +1787,7 @@ gui_line_hook_update (struct t_gui_line *line,
ptr_value2 = hashtable_get (hashtable2, "prefix");
if (ptr_value2 && (!ptr_value || (strcmp (ptr_value, ptr_value2) != 0)))
{
if (line->data->prefix)
string_shared_free (line->data->prefix);
string_shared_free (line->data->prefix);
line->data->prefix = (char *)string_shared_get (
(ptr_value2) ? ptr_value2 : "");
line->data->prefix_length = (line->data->prefix) ?
+10 -20
View File
@@ -593,14 +593,10 @@ gui_nicklist_remove_nick (struct t_gui_buffer *buffer,
(nick->group)->last_nick = nick->prev_nick;
/* free data */
if (nick->name)
string_shared_free (nick->name);
if (nick->color)
string_shared_free (nick->color);
if (nick->prefix)
string_shared_free (nick->prefix);
if (nick->prefix_color)
string_shared_free (nick->prefix_color);
string_shared_free (nick->name);
string_shared_free (nick->color);
string_shared_free (nick->prefix);
string_shared_free (nick->prefix_color);
buffer->nicklist_count--;
buffer->nicklist_nicks_count--;
@@ -674,10 +670,8 @@ gui_nicklist_remove_group (struct t_gui_buffer *buffer,
}
/* free data */
if (group->name)
string_shared_free (group->name);
if (group->color)
string_shared_free (group->color);
string_shared_free (group->name);
string_shared_free (group->color);
if (buffer->nicklist_display_groups && group->visible)
{
@@ -997,8 +991,7 @@ gui_nicklist_group_set (struct t_gui_buffer *buffer,
if (strcmp (property, "color") == 0)
{
if (group->color)
string_shared_free (group->color);
string_shared_free (group->color);
group->color = (value[0]) ? (char *)string_shared_get (value) : NULL;
group_changed = 1;
}
@@ -1108,22 +1101,19 @@ gui_nicklist_nick_set (struct t_gui_buffer *buffer,
if (strcmp (property, "color") == 0)
{
if (nick->color)
string_shared_free (nick->color);
string_shared_free (nick->color);
nick->color = (value[0]) ? (char *)string_shared_get (value) : NULL;
nick_changed = 1;
}
else if (strcmp (property, "prefix") == 0)
{
if (nick->prefix)
string_shared_free (nick->prefix);
string_shared_free (nick->prefix);
nick->prefix = (value[0]) ? (char *)string_shared_get (value) : NULL;
nick_changed = 1;
}
else if (strcmp (property, "prefix_color") == 0)
{
if (nick->prefix_color)
string_shared_free (nick->prefix_color);
string_shared_free (nick->prefix_color);
nick->prefix_color = (value[0]) ? (char *)string_shared_get (value) : NULL;
nick_changed = 1;
}
+3
View File
@@ -2902,6 +2902,9 @@ TEST(CoreString, Shared)
string_shared_free (str3);
LONGS_EQUAL(count + 0, string_hashtable_shared->items_count);
/* test free of NULL */
string_shared_free (NULL);
}
/*