diff options
author | James Booth <boothj5@gmail.com> | 2013-07-31 19:32:58 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-07-31 19:32:58 +0100 |
commit | 51b2137705b99ad45a8d4d646da9f3f8e2b3b4db (patch) | |
tree | d59284c75c94c2bdf029aabd1591593ef8f02f77 /src/jid.c | |
parent | 992ee280916f4218b4eefb87bc5a53b27e1cc47b (diff) | |
parent | 7b37f2ace7536ae12f1726819cb0b6224232361c (diff) | |
download | profani-tty-51b2137705b99ad45a8d4d646da9f3f8e2b3b4db.tar.gz |
Merge remote-tracking branch 'dmitry/memleaks' into nextdev
Diffstat (limited to 'src/jid.c')
-rw-r--r-- | src/jid.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/jid.c b/src/jid.c index 6347f083..b236c164 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,12 +108,12 @@ 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); + GFREE_SET_NULL(jid->str); + GFREE_SET_NULL(jid->localpart); + GFREE_SET_NULL(jid->domainpart); + GFREE_SET_NULL(jid->resourcepart); + GFREE_SET_NULL(jid->barejid); + GFREE_SET_NULL(jid->fulljid); FREE_SET_NULL(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; +} |