about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-10-22 12:55:17 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-10-22 12:56:15 +0300
commit135a4cd9e63de2047fb667e8c49f3a60cf341031 (patch)
treedeabd8cd9d118df49f9f7b8a396294769ea57e29
parent6bca96f041ffdaad4716c5afcf23ba6620fb587e (diff)
downloadprofani-tty-135a4cd9e63de2047fb667e8c49f3a60cf341031.tar.gz
Fix segfault when loading from MAM
When loading messages from MAM profanity would segfault. Reason was that
we were freeing the timestamp of messages when displaying them and we
needed it for loading MAM.
-rw-r--r--src/ui/window.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index dc37a5f1..dd40a534 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -2056,9 +2056,20 @@ win_redraw(ProfWin* window)
 void
 win_print_loading_history(ProfWin* window)
 {
-    GDateTime* timestamp = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0)->time : g_date_time_new_now_local();
+    GDateTime* timestamp;
+    gboolean is_buffer_empty = buffer_size(window->layout->buffer) == 0;
+
+    if (!is_buffer_empty) {
+        timestamp = buffer_get_entry(window->layout->buffer, 0)->time;
+    } else {
+        timestamp = g_date_time_new_now_local();
+    }
+
     buffer_prepend(window->layout->buffer, "-", 0, timestamp, NO_DATE, THEME_ROOMINFO, NULL, NULL, LOADING_MESSAGE, NULL, NULL);
-    g_date_time_unref(timestamp);
+
+    if (is_buffer_empty)
+        g_date_time_unref(timestamp);
+
     win_redraw(window);
 }