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

@@ -296,7 +296,7 @@ log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_las
// null the current time is used. from_start gets first few messages if true
// otherwise the last ones. Flip flips the order of the results
GSList*
log_database_get_previous_chat(const gchar* const contact_barejid, const char* start_time, char* end_time, gboolean from_start, gboolean flip)
log_database_get_previous_chat(const gchar* const contact_barejid, const char* start_time, const char* end_time, gboolean from_start, gboolean flip)
{
sqlite3_stmt* stmt = NULL;
const Jid* myjid = connection_get_jid();
@@ -306,7 +306,7 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const char* s
// Flip order when querying older pages
gchar* sort1 = from_start ? "ASC" : "DESC";
gchar* sort2 = !flip ? "ASC" : "DESC";
auto_gchar gchar* end_date_fmt = end_time ? end_time : prof_date_time_format_iso8601(NULL);
auto_gchar gchar* end_date_fmt = end_time ? g_strdup(end_time) : prof_date_time_format_iso8601(NULL);
auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM ("
"SELECT COALESCE(B.`message`, A.`message`) AS message, "
"A.`timestamp`, A.`from_jid`, A.`from_resource`, A.`to_jid`, A.`to_resource`, A.`type`, A.`encryption`, A.`stanza_id` FROM `ChatLogs` AS A "