From f5c2c81142605999f91181a359162d4689f9898a Mon Sep 17 00:00:00 2001 From: "Andrey (Stanson) Kozin" Date: Mon, 8 Feb 2016 08:56:09 +0300 Subject: [PATCH] Added conn_send_queue_purge() function. Function frees all data and clean send queue in xmpp_conn_release() xmpp_connect_client() xmpp_connect_component() --- src/conn.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/conn.c b/src/conn.c index b8138bf..1f6501d 100644 --- a/src/conn.c +++ b/src/conn.c @@ -59,6 +59,7 @@ static void _handle_stream_stanza(xmpp_stanza_t *stanza, void * const userdata); static unsigned short _conn_default_port(xmpp_conn_t * const conn, xmpp_conn_type_t type); +static void _conn_send_queue_purge(xmpp_conn_t * const conn); static int _conn_connect(xmpp_conn_t * const conn, const char * const domain, const char * const host, @@ -221,7 +222,6 @@ void xmpp_conn_set_keepalive(xmpp_conn_t * const conn, int timeout, int interval int xmpp_conn_release(xmpp_conn_t * const conn) { xmpp_ctx_t *ctx; - xmpp_send_queue_t *sq, *tsq; xmpp_connlist_t *item, *prev; xmpp_handlist_t *hlitem, *thli; hash_iterator_t *iter; @@ -303,14 +303,7 @@ int xmpp_conn_release(xmpp_conn_t * const conn) parser_free(conn->parser); - /* free queued */ - sq = conn->send_queue_head; - while (sq) { - tsq = sq; - sq = sq->next; - xmpp_free(ctx, tsq->data); - xmpp_free(ctx, tsq); - } + _conn_send_queue_purge(conn); if (conn->domain) xmpp_free(ctx, conn->domain); if (conn->jid) xmpp_free(ctx, conn->jid); @@ -971,6 +964,21 @@ static unsigned short _conn_default_port(xmpp_conn_t * const conn, }; } +static void _conn_send_queue_purge(xmpp_conn_t * const conn) +{ + xmpp_ctx_t *ctx = conn->ctx; + xmpp_send_queue_t *sq, *tsq; + + /* free queued */ + sq = conn->send_queue_head; + while (sq) { + tsq = sq; + sq = sq->next; + xmpp_free(ctx, tsq->data); + xmpp_free(ctx, tsq); + } +} + static int _conn_connect(xmpp_conn_t * const conn, const char * const domain, const char * const host, @@ -987,6 +995,8 @@ static int _conn_connect(xmpp_conn_t * const conn, if (conn->domain != NULL) xmpp_free(conn->ctx, conn->domain); + _conn_send_queue_purge(conn); + conn->type = type; conn->secured = 0; conn->tls_failed = 0;