Mercurial > pidgin
comparison src/protocols/simple/sipmsg.c @ 11439:617e67e1c985
[gaim-migrate @ 13676]
Fixed a couple leaks and potential leaks. The retval of g_strsplit() needs to be g_strfreev()'d. Also some "declaration after code" fixes.
committer: Tailor Script <tailor@pidgin.im>
| author | Daniel Atallah <daniel.atallah@gmail.com> |
|---|---|
| date | Sun, 04 Sep 2005 18:05:48 +0000 |
| parents | 90290f579926 |
| children | 0d18fa6c3b41 |
comparison
equal
deleted
inserted
replaced
| 11438:5451fe2d89c0 | 11439:617e67e1c985 |
|---|---|
| 54 gchar *dummy2; | 54 gchar *dummy2; |
| 55 gchar *tmp; | 55 gchar *tmp; |
| 56 int i=1; | 56 int i=1; |
| 57 parts = g_strsplit(lines[0], " ", 3); | 57 parts = g_strsplit(lines[0], " ", 3); |
| 58 if(!parts[0] || !parts[1] || !parts[2]) { | 58 if(!parts[0] || !parts[1] || !parts[2]) { |
| 59 g_strfreev(parts); | |
| 60 g_strfreev(lines); | |
| 59 g_free(msg); | 61 g_free(msg); |
| 60 return NULL; | 62 return NULL; |
| 61 } | 63 } |
| 62 if(strstr(parts[0],"SIP")) { // numeric response | 64 if(strstr(parts[0],"SIP")) { // numeric response |
| 63 msg->method = g_strdup(parts[2]); | 65 msg->method = g_strdup(parts[2]); |
| 69 } | 71 } |
| 70 g_strfreev(parts); | 72 g_strfreev(parts); |
| 71 for(i=1; lines[i] && strlen(lines[i])>2; i++) { | 73 for(i=1; lines[i] && strlen(lines[i])>2; i++) { |
| 72 parts = g_strsplit(lines[i], ":", 2); | 74 parts = g_strsplit(lines[i], ":", 2); |
| 73 if(!parts[0] || !parts[1]) { | 75 if(!parts[0] || !parts[1]) { |
| 76 g_strfreev(parts); | |
| 77 g_strfreev(lines); | |
| 74 g_free(msg); | 78 g_free(msg); |
| 75 return NULL; | 79 return NULL; |
| 76 } | 80 } |
| 77 dummy = parts[1]; | 81 dummy = parts[1]; |
| 78 dummy2 = 0; | 82 dummy2 = 0; |
| 87 dummy2 = tmp; | 91 dummy2 = tmp; |
| 88 } | 92 } |
| 89 sipmsg_add_header(msg, parts[0], dummy2); | 93 sipmsg_add_header(msg, parts[0], dummy2); |
| 90 g_strfreev(parts); | 94 g_strfreev(parts); |
| 91 } | 95 } |
| 96 g_strfreev(lines); | |
| 92 msg->bodylen = strtol(sipmsg_find_header(msg, "Content-Length"),NULL,10); | 97 msg->bodylen = strtol(sipmsg_find_header(msg, "Content-Length"),NULL,10); |
| 93 if(msg->response) { | 98 if(msg->response) { |
| 94 tmp = sipmsg_find_header(msg, "CSeq"); | 99 tmp = sipmsg_find_header(msg, "CSeq"); |
| 95 if(!tmp) { | 100 if(!tmp) { |
| 96 // SHOULD NOT HAPPEN | 101 // SHOULD NOT HAPPEN |
| 111 gaim_debug(GAIM_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen); | 116 gaim_debug(GAIM_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen); |
| 112 if(msg->target) gaim_debug(GAIM_DEBUG_MISC, "simple", "target: %s\n",msg->target); | 117 if(msg->target) gaim_debug(GAIM_DEBUG_MISC, "simple", "target: %s\n",msg->target); |
| 113 cur = msg->headers; | 118 cur = msg->headers; |
| 114 while(cur) { | 119 while(cur) { |
| 115 elem = cur->data; | 120 elem = cur->data; |
| 116 gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); | 121 gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); |
| 117 cur = g_slist_next(cur); | 122 cur = g_slist_next(cur); |
| 118 } | 123 } |
| 119 } | 124 } |
| 120 | 125 |
| 121 char *sipmsg_to_string(struct sipmsg *msg) { | 126 char *sipmsg_to_string(struct sipmsg *msg) { |
| 122 gchar *out; | 127 gchar *out; |
| 123 gchar *old; | 128 gchar *old; |
| 124 GSList *cur; | 129 GSList *cur; |
| 125 struct siphdrelement *elem; | 130 struct siphdrelement *elem; |
| 127 else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target); | 132 else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target); |
| 128 cur = msg->headers; | 133 cur = msg->headers; |
| 129 while(cur) { | 134 while(cur) { |
| 130 elem = cur->data; | 135 elem = cur->data; |
| 131 old = out; | 136 old = out; |
| 132 out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value); | 137 out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value); |
| 133 g_free(old); | 138 g_free(old); |
| 134 cur = g_slist_next(cur); | 139 cur = g_slist_next(cur); |
| 135 } | 140 } |
| 136 old = out; | 141 old = out; |
| 137 out = g_strdup_printf("%s\r\n",out); | 142 out = g_strdup_printf("%s\r\n",out); |
| 148 struct siphdrelement *element = g_new0(struct siphdrelement,1); | 153 struct siphdrelement *element = g_new0(struct siphdrelement,1); |
| 149 element->name = g_strdup(name); | 154 element->name = g_strdup(name); |
| 150 element->value = g_strdup(value); | 155 element->value = g_strdup(value); |
| 151 msg->headers = g_slist_append(msg->headers, element); | 156 msg->headers = g_slist_append(msg->headers, element); |
| 152 } | 157 } |
| 153 | 158 |
| 154 void sipmsg_free(struct sipmsg *msg) { | 159 void sipmsg_free(struct sipmsg *msg) { |
| 155 struct siphdrelement *elem; | 160 struct siphdrelement *elem; |
| 156 while(msg->headers) { | 161 while(msg->headers) { |
| 157 elem = msg->headers->data; | 162 elem = msg->headers->data; |
| 158 msg->headers = g_slist_remove(msg->headers,elem); | 163 msg->headers = g_slist_remove(msg->headers,elem); |
