summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/core-hdata.c3
-rw-r--r--src/gui/gui-chat.c3
-rw-r--r--src/gui/gui-line.c6
-rw-r--r--src/gui/gui-nicklist.c30
-rw-r--r--tests/unit/core/test-core-string.cpp3
5 files changed, 17 insertions, 28 deletions
diff --git a/src/core/core-hdata.c b/src/core/core-hdata.c
index cd4d28569..ad80ed805 100644
--- a/src/core/core-hdata.c
+++ b/src/core/core-hdata.c
@@ -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;
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index 77b29c6d1..7f1831d65 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -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);
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index 58a42a448..cc15da88e 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -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) ?
diff --git a/src/gui/gui-nicklist.c b/src/gui/gui-nicklist.c
index 7e43f4275..e696eb8f5 100644
--- a/src/gui/gui-nicklist.c
+++ b/src/gui/gui-nicklist.c
@@ -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;
}
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 580fc64ce..73750c0ab 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -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);
}
/*