diff options
Diffstat (limited to 'src/jid.c')
-rw-r--r-- | src/jid.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/jid.c b/src/jid.c index 6347f083..6840b64b 100644 --- a/src/jid.c +++ b/src/jid.c @@ -34,13 +34,14 @@ jid_create(const gchar * const str) { Jid *result = NULL; - if (str == NULL) { + /* if str is NULL g_strdup returns NULL */ + gchar *trimmed = g_strdup(str); + if (trimmed == NULL) { return NULL; } - gchar *trimmed = g_strdup(str); - if (strlen(trimmed) == 0) { + g_free(trimmed); return NULL; } @@ -50,10 +51,12 @@ jid_create(const gchar * const str) } if (!g_utf8_validate(trimmed, -1, NULL)) { + g_free(trimmed); return NULL; } result = malloc(sizeof(struct jid_t)); + result->str = NULL; result->localpart = NULL; result->domainpart = NULL; result->resourcepart = NULL; @@ -81,13 +84,11 @@ jid_create(const gchar * const str) } if (result->domainpart == NULL) { - free(trimmed); + jid_destroy(result); return NULL; } - result->str = g_strdup(trimmed); - - free(trimmed); + result->str = trimmed; return result; } @@ -107,13 +108,13 @@ void jid_destroy(Jid *jid) { if (jid != NULL) { - FREE_SET_NULL(jid->str); - FREE_SET_NULL(jid->localpart); - FREE_SET_NULL(jid->domainpart); - FREE_SET_NULL(jid->resourcepart); - FREE_SET_NULL(jid->barejid); - FREE_SET_NULL(jid->fulljid); - FREE_SET_NULL(jid); + g_free(jid->str); + g_free(jid->localpart); + g_free(jid->domainpart); + g_free(jid->resourcepart); + g_free(jid->barejid); + g_free(jid->fulljid); + free(jid); } } @@ -181,17 +182,17 @@ char * get_room_from_full_jid(const char * const full_room_jid) { char **tokens = g_strsplit(full_room_jid, "/", 0); - char *room_part; + char *room_part = NULL; - if (tokens == NULL || tokens[0] == NULL) { - return NULL; - } else { - room_part = strdup(tokens[0]); + if (tokens != NULL) { + if (tokens[0] != NULL) { + room_part = strdup(tokens[0]); + } g_strfreev(tokens); - - return room_part; } + + return room_part; } /* @@ -203,16 +204,15 @@ char * get_nick_from_full_jid(const char * const full_room_jid) { char **tokens = g_strsplit(full_room_jid, "/", 0); - char *nick_part; + char *nick_part = NULL; - if (tokens == NULL || tokens[1] == NULL) { - return NULL; - } else { - nick_part = strdup(tokens[1]); + if (tokens != NULL) { + if (tokens[0] != NULL && tokens[1] != NULL) { + nick_part = strdup(tokens[1]); + } g_strfreev(tokens); - - return nick_part; } -} + return nick_part; +} |