about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-08-08 17:15:58 +0200
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-08-08 17:15:58 +0200
commit65acffcf072a80932ca178182bbd30c416bf3584 (patch)
treed052d16edf3a5d75c698f4d67dadfb2bc708a40b
parent082de1363813d504581fccbd1c203ab7269e79a5 (diff)
downloadprofani-tty-65acffcf072a80932ca178182bbd30c416bf3584.tar.gz
fixup 11f52ad5474c7adb7f11df5b0c318597e4150312
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
-rw-r--r--src/xmpp/connection.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 6ba3c935..71b31c9d 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -1000,11 +1000,14 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
 
         // lost connection for unknown reason
         if (conn.conn_status == JABBER_CONNECTED) {
+            int send_queue_len = xmpp_conn_send_queue_len(conn.xmpp_conn);
             log_debug("Connection handler: Lost connection for unknown reason");
             conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn);
-            conn.queued_messages = calloc(xmpp_conn_send_queue_len(conn.xmpp_conn) + 1, sizeof(*conn.queued_messages));
-            for (int n = 0; n < xmpp_conn_send_queue_len(conn.xmpp_conn); ++n) {
-                conn.queued_messages[n] = xmpp_conn_send_queue_drop_element(conn.xmpp_conn, XMPP_QUEUE_OLDEST);
+            if (send_queue_len > 0) {
+                conn.queued_messages = calloc(send_queue_len + 1, sizeof(*conn.queued_messages));
+                for (int n = 0; n < send_queue_len && conn.queued_messages[n]; ++n) {
+                    conn.queued_messages[n] = xmpp_conn_send_queue_drop_element(conn.xmpp_conn, XMPP_QUEUE_OLDEST);
+                }
             }
             session_lost_connection();