Fix potential double free.

Change `log_database_get_previous_chat()` to not take ownership of
`end_time`, so it's clear that whoever passes it in, has to free it.

Fixes: https://github.com/profanity-im/profanity/issues/2110
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2026-03-18 13:05:14 +01:00
parent 349de02b8c
commit 2240879956
5 changed files with 9 additions and 10 deletions

View File

@@ -558,10 +558,11 @@ _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
// first entry's timestamp in the buffer is used. Flip true to prepend to buffer.
// Timestamps should be in iso8601
gboolean
chatwin_db_history(ProfChatWin* chatwin, const char* start_time, char* end_time, gboolean flip)
chatwin_db_history(ProfChatWin* chatwin, const char* start_time, const char* end_time, gboolean flip)
{
if (!end_time) {
end_time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time);
auto_gchar gchar* end_time_ = NULL;
if (!end_time && buffer_size(((ProfWin*)chatwin)->layout->buffer) != 0) {
end_time = end_time_ = g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time);
}
GSList* history = log_database_get_previous_chat(chatwin->barejid, start_time, end_time, !flip, flip);

View File

@@ -119,7 +119,7 @@ void chatwin_set_incoming_char(ProfChatWin* chatwin, const char* const ch);
void chatwin_unset_incoming_char(ProfChatWin* chatwin);
void chatwin_set_outgoing_char(ProfChatWin* chatwin, const char* const ch);
void chatwin_unset_outgoing_char(ProfChatWin* chatwin);
gboolean chatwin_db_history(ProfChatWin* chatwin, const char* start_time, char* end_time, gboolean flip);
gboolean chatwin_db_history(ProfChatWin* chatwin, const char* start_time, const char* end_time, gboolean flip);
// MUC window
ProfMucWin* mucwin_new(const char* const barejid);

View File

@@ -682,11 +682,9 @@ win_page_down(ProfWin* window, int scroll_size)
if (bf_size != 0) {
ProfBuffEntry* last_entry = buffer_get_entry(window->layout->buffer, bf_size - 1);
auto_gchar gchar* start = g_date_time_format_iso8601(last_entry->time);
gchar* end_date = prof_date_time_format_iso8601(NULL);
auto_gchar gchar* end_date = prof_date_time_format_iso8601(NULL);
if (*scroll_state != WIN_SCROLL_REACHED_BOTTOM && !chatwin_db_history((ProfChatWin*)window, start, end_date, FALSE)) {
*scroll_state = WIN_SCROLL_REACHED_BOTTOM;
} else if (*scroll_state == WIN_SCROLL_REACHED_BOTTOM) {
g_free(end_date);
}
int offset = last_entry->y_end_pos - 1;