# HG changeset patch # User Daniel Atallah # Date 1136521036 0 # Node ID 33ed71b35a438ad84ea4d5a4a8e48a35817a3076 # Parent 258871a6260056fd12a27ee476d8231f30b4d6c1 [gaim-migrate @ 15090] similar clean up to use GString instead of allocating and freeing buffers every iteration. The same basic code is used in 3 places to do this, it probably should be consolidated. committer: Tailor Script diff -r 258871a62600 -r 33ed71b35a43 src/protocols/simple/sipmsg.c --- a/src/protocols/simple/sipmsg.c Fri Jan 06 03:39:21 2006 +0000 +++ b/src/protocols/simple/sipmsg.c Fri Jan 06 04:17:16 2006 +0000 @@ -125,30 +125,28 @@ } char *sipmsg_to_string(struct sipmsg *msg) { - gchar *out; - gchar *old; GSList *cur; + GString *outstr = g_string_new(""); struct siphdrelement *elem; - if(msg->response) out = g_strdup_printf("SIP/2.0 %d Unknown\r\n", msg->response); - else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target); + + if(msg->response) + g_string_append_printf(outstr, "SIP/2.0 %d Unknown\r\n", + msg->response); + else + g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", + msg->method, msg->target); + cur = msg->headers; while(cur) { elem = cur->data; - old = out; - out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value); - g_free(old); + g_string_append_printf(outstr, "%s: %s\r\n", elem->name, + elem->value); cur = g_slist_next(cur); } - old = out; - out = g_strdup_printf("%s\r\n",out); - g_free(old); - if(msg->bodylen) { - old = out; - out = g_strdup_printf("%s%s",out, msg->body); - g_free(old); - } - return out; + g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : ""); + + return g_string_free(outstr, FALSE); } void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) { struct siphdrelement *element = g_new0(struct siphdrelement,1);