about summary refs log tree commit diff stats
path: root/src/jid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/jid.c')
-rw-r--r--src/jid.c58
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;
+}
e86244ccef69e98419ba1a'>adaa28a ^
d4b7a9a ^




6a3ae5e ^
d4b7a9a ^


adaa28a ^
c47da14 ^
439e15d ^
9955ddc ^
dc5d967 ^
9955ddc ^



439e15d ^




16c67f3 ^
7711ab6 ^
e48de30 ^
439e15d ^

0464e42 ^
439e15d ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66