From 0653200965122c46be4f31996d2396b568ee8dcf Mon Sep 17 00:00:00 2001 From: swirl Date: Wed, 13 Oct 2021 15:02:05 -0400 Subject: registration: memory leaks, error checking --- src/xmpp/connection.c | 9 +++++---- src/xmpp/stanza.c | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/xmpp') diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index e478df1a..295c8bec 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -509,7 +509,7 @@ connection_register(const char* const altdomain, int port, const char* const tls log_warning("Failed to get libstrophe conn during connect"); return JABBER_DISCONNECTED; } - xmpp_conn_set_jid(conn.xmpp_conn, strdup(altdomain)); + xmpp_conn_set_jid(conn.xmpp_conn, altdomain); flags = xmpp_conn_get_flags(conn.xmpp_conn); @@ -542,9 +542,10 @@ connection_register(const char* const altdomain, int port, const char* const tls prof_reg_t *reg; - reg = malloc(sizeof(*reg)); - if (reg != NULL) { - memset(reg, 0, sizeof(*reg)); + reg = calloc(1, sizeof(*reg)); + if (reg == NULL) { + log_warning("Failed to allocate registration data struct during connect"); + return JABBER_DISCONNECTED; } reg->username = strdup(username); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 22835d1f..4849f3e1 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -2755,8 +2755,7 @@ xmpp_stanza_t* stanza_register_new_account(xmpp_ctx_t* ctx, const char* const user, const char* const password) { char* id = connection_create_stanza_id(); - //char* id = "reg2"; - xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, strdup(id)); + xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); free(id); xmpp_stanza_t* register_new_account = xmpp_stanza_new(ctx); -- cgit 1.4.1-2-gfad0