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

api: readjust string size in function string_dyn_free when string is not freed (issue #1875)

This frees some allocated memory if size_alloc was greater than size in the
dynamic string.
This commit is contained in:
Sébastien Helleu
2023-01-28 22:18:14 +01:00
parent 48c1aebb83
commit fa6a9bb934
5 changed files with 20 additions and 17 deletions
+1
View File
@@ -27,6 +27,7 @@ New features::
Bug fixes::
* core: fix display glitch in command errors when a wide char is set in option weechat.look.command_chars (issue #1871)
* api: readjust string size in function string_dyn_free when string is not freed
* irc: fix join of channels in "autojoin" server option on first connection to server if auto reconnection is performed (issue #1873)
* typing: fix crash when pointer buffer is not received in callback for signal "input_text_changed" (issue #1869)
+1 -4
View File
@@ -334,10 +334,7 @@ eval_string_range_chars (const char *range)
end:
if (string)
{
result = *string;
string_dyn_free (string, 0);
}
result = string_dyn_free (string, 0);
return (result) ? result : strdup ("");
}
+14 -5
View File
@@ -4409,7 +4409,6 @@ string_dyn_copy (char **string, const char *new_string)
if (!string_realloc)
return 0;
ptr_string_dyn->string = string_realloc;
*string = string_realloc;
ptr_string_dyn->size_alloc = new_size_alloc;
}
@@ -4475,7 +4474,6 @@ string_dyn_concat (char **string, const char *add, int bytes)
return 0;
}
ptr_string_dyn->string = string_realloc;
*string = string_realloc;
ptr_string_dyn->size_alloc = new_size_alloc;
}
@@ -4496,8 +4494,11 @@ string_dyn_concat (char **string, const char *add, int bytes)
* string_dyn_alloc or a string pointer modified by string_dyn_concat.
*
* If free_string == 1, the string itself is freed in the structure.
* Otherwise the pointer (*string) remains valid after this call, and
* the caller must manually free the string with a call to free().
*
* If free_string == 0, the pointer (*string) remains valid after this call,
* and the caller must manually free the string with a call to free().
* Be careful, the pointer in *string may change after this call because
* the string can be reallocated to its exact size.
*
* Returns the pointer to the string if "free_string" is 0 (string
* pointer is still valid), or NULL if "free_string" is 1 (string
@@ -4508,7 +4509,7 @@ char *
string_dyn_free (char **string, int free_string)
{
struct t_string_dyn *ptr_string_dyn;
char *ptr_string;
char *ptr_string, *string_realloc;
if (!string || !*string)
return NULL;
@@ -4522,6 +4523,14 @@ string_dyn_free (char **string, int free_string)
}
else
{
/* if needed, realloc the string to its exact size */
if (ptr_string_dyn->size_alloc > ptr_string_dyn->size)
{
string_realloc = realloc (ptr_string_dyn->string,
ptr_string_dyn->size);
if (string_realloc)
ptr_string_dyn->string = string_realloc;
}
ptr_string = ptr_string_dyn->string;
}
+3 -4
View File
@@ -574,8 +574,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
-1);
}
}
str_hotlist = *hotlist;
weechat_string_dyn_free (hotlist, 0);
str_hotlist = weechat_string_dyn_free (hotlist, 0);
}
}
weechat_hashtable_set (
@@ -655,15 +654,15 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
line_number++;
}
str_buflist = *buflist;
str_buflist = weechat_string_dyn_free (buflist, 0);
goto end;
error:
weechat_string_dyn_free (buflist, 1);
str_buflist = NULL;
end:
weechat_string_dyn_free (buflist, 0);
weechat_arraylist_free (buffers);
if ((line_number_current_buffer != old_line_number_current_buffer[item_index])
+1 -4
View File
@@ -372,10 +372,7 @@ irc_join_build_string (struct t_arraylist *arraylist)
end:
if (channels)
{
result = *channels;
weechat_string_dyn_free (channels, 0);
}
result = weechat_string_dyn_free (channels, 0);
if (keys)
weechat_string_dyn_free (keys, 1);